I understand the basic concept of IoC, but I have a hard time expanding my vision beyond the initial concept.
Basically, using a DI framework, I should not use anymore the new keyword for objects with dependencies, because then, I am not calling the DI framework resolving method, thus not triggering the chain of resolves.
User wants an object A who needs an object B who wants an object C who wants...
That is what would happen, using a DI Framework. But using the new keyword, I would get left with :
I just instantiate an object A
Question 1 : Am I right ? Wrong ? Or is it again a case of "it depends" ?
I just read an answer of Mark Seemann (https://stackoverflow.com/a/2490797/2671072) where he says :
A DI Container should resolve the entire dependency graph in the application's Composition Root and get out of the way.
Question 2 : Does he imply that the only time the DI framework should be called (to resolve something) is from the start of an application, and from there, everything should be fine, left alone ?
I am working on a project. But I have troubles defining where interfaces and classes (entities, value objects, implementations) should go (assemblies, namespace naming...).
Question 3 : Does DI imply a special structure for code organisation ?
I heard that domain/business layer should not reference any DI Framework.
Question 4 : Does that recommendation also apply to any other layer ? Or is it false ?
I am working with two libraries (say LibraryA and LibraryB). LibraryB contains three classes, ClassA, ClassB, ClassC. Each class depends on the previous (with ClassA being the root/aggregate). LibraryA depends on ClassA.
Question 5 : Is it better to create a factory inside LibraryB, dedicated in creating ClassA and its dependencies (using only new keyword), or would it be better to make full use of the DI framework, and manually register ClassA, ClassB, ClassC, and resolve ClassA ?