In my demo project I replaced the manual creation of a view controller with the factory-based creation within an assembly like so (as Jasper Blues demonstrated here: 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")
})
}
But the view controller still needs some other dependencies. How can I inject the propery when doing this?
And actually I have two questions: All IBOutlets are nil, when I try to use the view controller like this. Am I missing something?
Correct answer based on Jasper's response
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())
}
}