I am exploring dependency injection and the term composition root is used all over the place. So what is it?
相关问题
- Wrapping Angular components which has Parent/Child
- How to I access the DbContext of EF core from anot
- NserviceBus property injection
- How can I get all singleton instances from a Guice
- Unity and delegate
相关文章
- TinyIoC: Register multiple interfaces on a single
- Restlet server resource with constructor parameter
- Injecting an IEnumerable into a constructor with a
- ASP.NET Core DbContext injection
- DI container, factory, or new for ephemeral object
- How does @Inject in Scala work
- When to use interfaces, and when to use higher ord
- @EntityListeners Injection + jUnit Testing
Mark Seemann wrote a great article about Composition Root design pattern.
essential points from this article are:
http://blog.ploeh.dk/2011/07/28/CompositionRoot/
I wrote my own JavaScript Dependency Injection Framework called Di-Ninja with these principles in mind
https://github.com/di-ninja/di-ninja
As I know, is the only one in javascript that implement the Composition-Root design pattern and it's documentation could be another good example to demonstrate how it works.
It work with NodeJS, browser (with Webpack or UMD/AMD), and React-Native.
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:
There is a good answer here which explains a bit more about this.
See also this answer.