在我的演示项目中,我取代了手工创建与工厂为基础创建一个视图控制器的组件中,像这样(如碧玉蓝调证明这里: https://stackoverflow.com/a/24227246/397898 )
// ApplicationAssembly
dynamic func mainStoryboard() -> AnyObject {
return TyphoonDefinition.withClass(TyphoonStoryboard.self) {
(definition) in
definition.useInitializer("storyboardWithName:factory:bundle:") {
(initializer) in
initializer.injectParameterWith("Main")
initializer.injectParameterWith(self)
initializer.injectParameterWith(NSBundle.mainBundle())
}
definition.scope = TyphoonScope.Singleton
}
}
// PersonListAssembly
dynamic func personListViewController() -> AnyObject {
return TyphoonDefinition.withFactory(self.applicationAssembly.mainStoryboard(), selector: "instantiateViewControllerWithIdentifier:", parameters: {
(factoryMethod) in
factoryMethod.injectParameterWith("PersonListViewController")
})
}
但是视图控制器仍然需要一些其他的依赖。 我怎么能这样做时注入属性格式?
而实际上我有两个问题:所有IBOutlets是零,当我尝试使用这样的视图控制器。 我缺少的东西吗?
基于Jasper的响应正确答案
dynamic func personListViewController() -> AnyObject {
return TyphoonDefinition.withClass(PersonListViewController.self) {
(definition) in
definition.factory = self.applicationAssembly.mainStoryboard()
definition.useInitializer("instantiateViewControllerWithIdentifier:", parameters: { (factoryMethod) in
factoryMethod.injectParameterWith("PersonListViewController")
})
definition.injectProperty("presenter", with: self.personListPresenter())
}
}