3 ms·
> Dependency injection is particularly bad because it makes it difficult to find the path to the dependency's source code I agree. To me it seems that the pro
by pjc50 7y ago
> Dependency injection is particularly bad because it makes it difficult to find the path to the dependency's source code
I agree.
To me it seems that the problem is globals. In the Java example, it's convenient to think of "the bank" as global, right up to the point where it isn't (need to substitute a test service, or different banks for different regions etc.)
DI replaces global variables. "Magic" DI where this is handled invisibly by a framework lets you pretend it's still a global variable, with all the advantages and disadvantages of that.
I too prefer "explicit" DI where the dependencies are passed in. This does tend to lead to constructing a "world" object which carries around all the pseudo-global variables.
Perhaps this would benefit from language support in some way, just as Perl has $_ to allow non-explicit parameter passing.
- mcphage 7y ago> Perhaps this would benefit from language support in some way, Scala has implicit parameters, which are declared explicitly in your method signature, but aren't passed explicitly into the method call (so long as exist in scope as an implicit where the call occurs). They can be confusing, but they can also help.
- scarface74 7y agoI keep seeing posts about wanting “explicit” DI instead of “Magic” DI. The article’s author only showed examples of using constructor injection. No one is arguing that it should be done any other way.
- UK-Al05 7y agoMost DI frameworks you explicitly pass things in via the constructor. I don't get it.
- kixiQu 7y agoThere can be some magic with jpassing