|
|
|
|
|
by ivanche
2051 days ago
|
|
You're 100% right. People that complain about DI don't understand 2 simple facts: 1) that graph of object creation is NOT equal to graph of object usage 2) if you don't use DI, problems won't automagically go away - code will _still_ have dependencies, just they'll be hidden and tightly coupled |
|
It is precisely when you use a DI container that the problem is hidden, whether or not it's solved.
In most projects that use a DI container, the problem is usually not solved correctly, but the developers are oblivious and overconfident. They think, as you do, using a DI container means they did it right. False! The DI container only guarantees everything is hoisted up to the object constructor. This is NOT DEPENDENCY INVERSION. The objects can be in the constructor, but the dependency arrow can still point the wrong way. An obvious example of this I've seen a million times is an interface sitting right next to its only implementation. That's NOT Dependency Inversion.
If you don't use a DI container, the problem also may or may not be solved, but it is never obscured, it is completely visible.