Skip to content

Conversation

@mori-atsushi
Copy link
Collaborator

close #130
なぜか動きません。


var window: UIWindow?
lazy var applicationCoordinator = ApplicationCoordinator(window: self.window!)
lazy var coordinator = DependencyManager.getResolver().resolve(ApplicationCoordinator.self)!
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CoordinatorをDIするメリットがあまり思いつかなかったんだが,どういったメリットが有るんだろうか.

override func viewDidLoad() {
super.viewDidLoad()

print(viewModel)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

デバッグ時に使用していた記述が残っています.

private func setUpDataBinding() {
signInButton.rx.tap
.subscribe({ _ in self.viewModel?.onSignInClicked() })
.subscribe({ _ in self.viewModel.onSignInClicked() })
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

循環参照を起こします.
下記のように変更することを推奨します.

.subscribe({ [weak self] _ in self?.viewModel.onSignInClicked() })

import SwinjectStoryboard

class DependencyManager {
static let assembler = Assembler([
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

カプセル化を試みているなら,ここはprivateの方がいいかもしれないです.
また,この使用方法ならclassじゃなくてenumでも良いかも.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

また,この実装だとどこからでもDI出来てしまうが,それが実装意図に沿っているかも併せて気になりました.


class WelcomeViewModel {
var coordinator: WelcomeCoordinator?
let coordinator: WelcomeCoordinator
Copy link

@k-kohey k-kohey Mar 17, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CoordinatorがWelcomeViewControllerへの参照を持っていれば,循環参照が起きてそうだと思ったんだが,どうだろうか.
coordinatorはaqppDelegateに保持されているので,解放されることは無さそう.なので

private unowned let coordinator: WelcomeCoordinator

が良さそう.

一方で,ViewModelがCoordinatorを直接持つ必要も無さそうなので,外部から遷移ロジックを注入するのが一番安全かも.

class ViewControllerAssembly: Assembly {
func assemble(container: Container) {
container.storyboardInitCompleted(WelcomeViewConstoller.self) { res, viewController in
viewController.viewModel = res.resolve(WelcomeViewModel.self)!
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

抽象に依存してないが,これは実装意図に沿っているだろうか.
また,ここでランタイムエラーが起きないかも併せて気になりました.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

DI Containerを作成

3 participants