What is a composition root in the context of Dependency Injection
I am exploring dependency injection and the term composition root is used all over the place. So what is it?
The composition root is the single place in your application where the composition of the object graphs for your application take place, using the dependency injection container (although how this is done is irrelevant, it could be using a container or could be done manually using pure DI).
There should only be one place where this happens and your container should not need to be used outside of the composition root.
Quoting from one of the answers linked to below:
In practice, this means that you should configure the container at the root of your application.
There is a good answer here which explains a bit more about this.
See also this answer.
链接地址: http://www.djcxy.com/p/82278.html上一篇: 调用注入对象的方法
下一篇: 什么是依赖注入上下文中的组合根