From the Dependency Injection in .NET book I know that the object graph should be created at the Composition Root
of the application which makes a lot of sense to me when you are using an IoC Container
.
In all the applications I've seen when an attempt to use DI is being made, there are always two constructors:
- the one with the dependencies as parameters and
- the "default" one with no parameters which in turn calls the other one "newing" up all the dependencies
In the aforementioned book, however, this is called the "Bastard Injection anti-pattern" and that is what I used to know as "Poor Man's Injection".
Now considering all this, I would say then that "Poor Man's Injection" would be just not using an IoC Container
and instead coding all the object graph by hand on the said Composition Root
.
So my questions are:
- Am I understanding these concepts correctly or am I completely off track?
- If you still need to register all the dependencies in the IoC container vs. coding them by hand in the exact same Composition Root, what's the real benefit of using an IoC container?
- If I have misunderstood what "Poor Man's Injection" really is, could someone please clarify it?