Hacker News new | ask | show | jobs
by mrkeen 1197 days ago
I feel exactly the same way about DI.

Structuring code so that abstractions don't depend upon implementation details is in my top 3 principles of all time (along with pure functions and good typing).

DI frameworks a la Spring and Guice just annoy me.

2 comments

Yep. And then you get bloated constructors taking in a dozen arguments many of which are just needed to pass along to the parent class constructor, and - drum roll - the CI tools complain because your constructor is similar to one in another completely different class that just happens to need similar dependencies due to the abstractions and that's a copy-paste-detection fail.

So you refactor everything, factor out the constructor, and then it passes but now you need to add a new dependency so you're right back to the same nonsense. And/or you have tons of classes getting dependencies they don't even need, because some do so the parent has to have them all.

Traits can help some.

But the abstractions and DI that were supposed to make things easier still often make things more complicated.

DI has a place. In my opinion it's for plugin systems. If you have a core system that enables third parties to extend DI can be brilliant.