Hacker News new | ask | show | jobs
by revscat 4425 days ago
Dependency injection has seen its day. The gains promised by DI/IoC containers tend to be outweighed by the complexity they introduce.

I'm looking at you, Spring.

3 comments

Adding @Inject is hard now?

Most DI frameworks automatically configure, and register objects. So literally all you need to add is the annotation.

Then you can override the automatic registration with you own, with different implementation when required.

Spring's DI is terrible but Guice (and on mobile, Dagger) is really easy to work with, statically typed and has increased the maintainability and testability of our code base tremendously.
DI is fine, it's just the way people overuse it that's an abomination. I general inject the most significant pieces, or the pieces that are changed. I won't even introduce DI unless I know I'm going to setup a different config of it. My coworkers (sigh), insist that nearly everything must be injected to "eliminate dependencies". (and because it makes it "easier to test"). YMMV