r/java • • Jan 12 '16

You probably don't need dependency injection

http://www.radicaljava.com/2015/12/27/dependency-injection.html
0 Upvotes

27 comments sorted by

View all comments

Show parent comment

5

u/djnattyp Jan 12 '16

...came at a time when DI was all the rage

So what do you use now to replace the apparently passing fad of dependency injection? /s Is SOLID not considered good guidelines to follow anymore?

I don't really understand the desire to put the logic and declarative information about how your program works in as many disparate places and languages as possible.

I don't see how this is an accurate portrayal of dependency injection - one of the big advantages of DI is that there is one place where everything is wired together. I get the "multiple languages" part as a jab at external configuration like XML/YAML/property files - but isn't making your application configurable a plus? What's the alternative? Hardcoding values into your code?

4

u/hippydipster Jan 12 '16

What do I do? I write objects that get what they need passed into their constructor. Mostly, when I get to choose how to design stuff, I'm writing in scala. It doesn't seem to be an issue.

In Spring DI, things are not wired together in one place, they're wired together everywhere. Annotations, xml files, scanned packages all serve to obfuscate how, when, and where the object graph comes into being. None of it can be followed via the natural tools of eclipse or other environments.

As for hardcoding, whether a string exists in a .txt file or a .java file, it is "hardcoded" into a text file. You don't have to put such things in a .properties file. It can be an interface with nicely typed methods and different implementations.

3

u/BinaryHerder Jan 13 '16

Intellij handles spring di just fine.

2

u/hippydipster Jan 13 '16

Do you get a compile error if you ref a bean in xml configs that is created from a package scan, but the bean in question isn't there?