-
Notifications
You must be signed in to change notification settings - Fork 268
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
Assembly and Storyboard-Created ViewControllers #85
Comments
There are two ways: a) A simple way. Create a 'recipe' in either XML or assembly style. Obtain the controller from the story board. Tell Typhoon to inject dependencies. b) A more stream-lined way. Use the TyphoonStoryBoard factory component. . . This way you just ask for the controller from Typhoon like a normal component. I believe @eriksundin has some examples. Let me see if I can dig them up. . . Bump if you don't hear back within a few hours. BTW: I'll be setting up a mailing list very soon. |
There is currently a -injectProperties: method on the component factory that you can use to apply dependency injection on a component after it has been instantiated, ex. by the story board. I know the TyphoonStoryBoard has been discussed in #15 , not sure if that component was ever merged into the project though? For now, you could subclass UIStoryboard and call the -injectProperties: on the view controller by overriding: – instantiateInitialViewController
– instantiateViewControllerWithIdentifier:
// Example
- (id)instantiateViewControllerWithIdentifier:(NSString *)identifier {
id instantiatedViewController = [super instantiateViewControllerWithIdentifier:identifier];
[[TyphoonComponentFactory defaultFactory] injectProperties:instantiatedViewController];
return instantiatedViewController;
}
|
@fabb, @eriksundin - apologies - I thought that I saw and evaluated a pull request TyphoonStoryBoard last week. . But digging around just now it appears that its still pending implementation. . . we'll get to it as soon as we can. .sorry for the oversight - I've been busy with two client projects, but will be spending more time on Typhoon soon. Meantime, you can resolve a view controller from the StoryBoard and then inject dependencies. . . @fabb do you need some help with this? |
Wow, this sounds awesome. Still, as a DI beginner, one question: As far as I have understood, injecting would be used to inject global objects used throughout the application. Would the concept also be useful for the case a viewcontroller is being configured by the preceding view controller? I.e. View controller A can both be shown by Viewcontrollers B and C, and when B shows A, it configures it differently than when C shows A (i.e. show some additional toolbar button)?
You mean using |
Exactly, the DI container will manage and wire up the dependencies between components in your application. Isolating the configuration to one place in your app. In the case you describe, my personal opinion, is that it sounds more like a closed context-configuration. Which I would put in the presenting controller. So Typhoon helps you make sure the controller is set up properly and have every dependency and configuration it needs. Then you can give it more information about in what context it will be presented before it will happen. |
@eriksundin That is exactly right. You might have some view controllers set up to have the following common components:
And then at Runtime you'd want to provide, say a FlightDetails object from ViewControllerA to ViewControllerB, after having resolved it from Typhoon. Up until a while ago this was the way I'd always done it. However, one of our uses recently opened a ticket about autofac-style paramerter injection. This means that Typhoon will build the component as-per the recipe, and also allow some parameters that you can pass is some arguments to the container at run-time, which will also be added to the component. . so that its ready for use in a single step. There are a couple of benefits you can get by passing these arguments via the container, rather than just injecting them manually after resolving, as described in: #23 and #47 . . so this feature is in the backlog. |
moved this question to stackoverflow: http://stackoverflow.com/questions/18998759/typhoon-assembly-and-storyboard-created-viewcontrollers/18998809#18998809 . . and created a Typhoon tag there. (Thanks Erik for the suggestion). |
Sorry — I've sort of just run into this and I don't quite understand what the recommended way of passing information from one view controller to the next is. I just can't really imagine what the code would look like. @jasperblues Are you saying that TyphoonStoryboard users still have to use I've posted a separate question onto SO that deals with this very specific case. |
@fatuhoku Answered your question on SO, let us know if it helps. |
I'm trying to wrap my head around direct injection, assemblies and the like, but there's still much to grasp for me. For the beginning, how would I use DI with iOS storyboards where view controllers are generated implicitly by the system? Would I have to do something special in the prepareForSegue methods?
The text was updated successfully, but these errors were encountered: