-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[WIP] DI containerの設定 #138
base: new-architecture
Are you sure you want to change the base?
Conversation
|
||
@UIApplicationMain | ||
class AppDelegate: UIResponder, UIApplicationDelegate { | ||
|
||
var window: UIWindow? | ||
lazy var applicationCoordinator = ApplicationCoordinator(window: self.window!) | ||
lazy var coordinator = DependencyManager.getResolver().resolve(ApplicationCoordinator.self)! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
CoordinatorをDIするメリットがあまり思いつかなかったんだが,どういったメリットが有るんだろうか.
|
||
@IBOutlet weak var signInButton: UIBarButtonItem! | ||
@IBOutlet weak var signUpButton: UIBarButtonItem! | ||
|
||
override func viewDidLoad() { | ||
super.viewDidLoad() | ||
|
||
print(viewModel) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
デバッグ時に使用していた記述が残っています.
setUpDataBinding() | ||
} | ||
|
||
private func setUpDataBinding() { | ||
signInButton.rx.tap | ||
.subscribe({ _ in self.viewModel?.onSignInClicked() }) | ||
.subscribe({ _ in self.viewModel.onSignInClicked() }) |
There was a problem hiding this comment.
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([ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
カプセル化を試みているなら,ここはprivateの方がいいかもしれないです.
また,この使用方法ならclassじゃなくてenumでも良いかも.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
また,この実装だとどこからでもDI出来てしまうが,それが実装意図に沿っているかも併せて気になりました.
@@ -9,13 +9,16 @@ | |||
import Foundation | |||
|
|||
class WelcomeViewModel { | |||
var coordinator: WelcomeCoordinator? | |||
let coordinator: WelcomeCoordinator |
There was a problem hiding this comment.
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)! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
抽象に依存してないが,これは実装意図に沿っているだろうか.
また,ここでランタイムエラーが起きないかも併せて気になりました.
close #130
なぜか動きません。