Clean iOS Architecture 101: Composition Root
Articles Blog

Clean iOS Architecture 101: Composition Root

October 27, 2019

Caio: What is Composition Root? After you have designed and declared your components… And you have laid out the dependencies nicely. Using Constructor Injection and the other methods. Then someone needs to instantiate these objects. So the Composition Root dictates that there is… A single centralized place and all the instantiation will happen in there. Caio: So Composition Root is a centralized place… Where objects should be instantiated and composed. Because you can follow all the principles to separate your modules… You create clean boundaries between them with abstract interfaces, protocols, closures… But at some point you need to compose all of them together so your app can run. If you create the clean interfaces and the abstractions… But you instantiate the dependencies inside the components… You break the whole separation. That’s why you move all the composition and instantiation to one centralized place. Normally in Main. The main function that starts the whole application. That’s the place where you inject all the dependencies. Either manually or using a Dependency Injection Container. Mike: Right! And if you’re using a Dependency Injection Container… The Composition Root is the place to use that throughout the application.

Only registered users can comment.

  1. On September 23, 25, and 27, Caio and Mike will teach you how to find fantastic iOS opportunities, double your income, and work with remarkable people. Register now:

  2. How does one go about this in a mobile environment where memory is tightly constrained? Should all ViewControllers and their dependencies be created at startup time?

Leave a Reply

Your email address will not be published. Required fields are marked *