Composition Root
A classic solution to the problem of creating the dependencies is using a pattern called Composition Root.
The Composition Root is a place in the code where components of different layers are wired together. The reason to have in a separate place is to not mix configuration logic and the other different kind of logic, like the business logic that defines the behavior of the software. The only responsibility of the Composition Root pattern is to instantiate and configure other components. The Injections of the dependencies, either in the constructor or in properties, must be done in the Composition Root. In the following diagram, we can see that the Composition Root is a particular layer that has the responsibility of composing ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access