Passing dependencies through Coordinator chain

As described in the original post about Coordinators and MVC-C architecture, the top logical entity in your app should be AppCoordinator.

This Coordinator will then create and keep references to instances of other coordinators; either directly keeping references to them or through childCoordinators.

Apart from AppCoordinator, most other Coordinators are most likely content-oriented. Which means they will have a set of UIViewControllers that they display for specific purpose. How they do that – create UIVCs, present them etc – it’s their own business so it makes no sense to expose that as public. However, there should be a way for other coordinators to specify the desired content.
Example: remote notification handler may instruct you to display a specific promo offer inside CartCoordinator.

This concept of the content page/view, I modeled through simple enumeration inside each content Coordinator, like this:

CartCoordinator will fetch the offer using provided offerId from the remote notification and push the appropriate UIViewController.

To do that, it will probably need access to some DataManager and/or APIManager. Instances of those objects are kept at AppCoordinator and are passed-down using that one line of code I sneaked in the previous code snippet:

And that’s about it. In the next post in the Coordinator series I’ll explain how to use AppDependency with UIViewController and especially how to handle the case where some of the dependencies may not yet be available when it’s requested.

As always, keep an eye on Coordinator repo as I keep adding small fixes and refinements.