appsquickly / typhoon

Powerful dependency injection for Objective-C ✨✨ (https://PILGRIM.PH is the pure Swift successor to Typhoon!!)✨✨
https://pilgrim.ph
Apache License 2.0
2.7k stars 269 forks source link

Wiring embedded view controllers with parent instantiated from storyboard #550

Closed RomanTruba closed 7 years ago

RomanTruba commented 7 years ago

I'm trying to implement different VIPER modules on one screen. In storyboards a view controller can contain a container view with another view controller connected by "Embed segue". The question is how to implement assembly which will inject main view controller's "presenter" (which is a property of a view controller) to embedded view controller's "presenter" when we instantiate it from storyboard? I know, I can extract it from parent by overriding "didMoveToParentViewController:" but it will lead to unwanted coupling.

alexgarbarev commented 7 years ago

you can declare collaborating assemblies inside any assembly as properties. For example you can declare property of Child assembly inside Parent assembly and wise versa. Using that you can inject parent presenter as module output for child.

RomanTruba commented 7 years ago

@alexgarbarev thanks for response. Actually, I tried it before. As the result, it will lead to new objects creation, instead of wiring existing objects. For example, Child will have another parent presenter object, not the one Parent owns.

RomanTruba commented 7 years ago

After some time, I found out my problem is different from DI, and depends more from runtime segues. So I used ViperMcFlurry with some changes.