9 ms·
>Dependency injection is particularly bad because it makes it difficult to find the path to the dependency's source code Can you expand? Not sure I understand.
by protonimitate 7y ago
>Dependency injection is particularly bad because it makes it difficult to find the path to the dependency's source code
Can you expand? Not sure I understand. Is it more difficult because the dependency is separate by an abstraction layer? Imo if DI is done right, the dependencies are always explicitly injected so there shouldn't really be any confusion about what the 'source' is.
- PeterisP 7y agoThey're explicitly injected somewhere. That somewhere often is distant both in time and space from where the dependency is used - for example, if the injection happened when that object was constructed as in the example which the original article used. If many injections are possible, then I'm in a debugger breakpoint in the code where it's used, I don't have access to the call stack of how, where and why the object was injected with that dependency. If it's usually just "the one" dependency except when testing, then if I'm looking at the code of a particular function, I don't have an easy way to see the code that must always get executed there because it "could" be (but isn't) anything.