Reputation: 579
I'm quite new to DI and IoC Containers. I understand that the IoC container should only life at the composition root of the project. And I understand that all other projects in the solution shouldn't have a reference to the IoC container.
So far so good....
Then I thought about, how to create new objects at runtime after the bootstrap.
I found this two articles:
http://blog.ploeh.dk/2012/03/15/ImplementinganAbstractFactory/
http://netpl.blogspot.de/2012/12/di-factories-and-composition-root.html
If I'm right, I have to create a factory for each object I want to instantiate at runtime, after the bootstrap. These factories gets the IoC Container injected.
Thus the project of the factory has to reference the IoC-Library (because of the constructor injection).
Finally I'm confused!
Where do these factories live (in which project)? I wonder, since all other projects (beside the composition root project) shouldn't have a reference to the IoC- Library.
At which point I'm wrong?
Upvotes: 1
Views: 757
Reputation: 172646
Where do these factories live (in which project)? I wonder, since all other projects (beside the composition root project) shouldn't have a reference to the IoC- Library.
If the factory implementation needs to reference the container, it has to be defined in the Composition Root. The factory abstraction, however, can be defined in the layer where it is needed.
Upvotes: 1