News for hackers. Stuff that matters.
Re:Dependency Injection is Evil (2011) by sk5t on Sunday April 12, 2015 @11:12AM (#9363584)
Good use of DI can help one write a more comprehensible, lighter, more flexible system, where each class is responsible for doing just one or two reasonably-scoped tasks. Unlike, say, an obsession with UML, DI is _not_ the hallmark of a crap-grade programmer. Nor is it all that simple, in the sense that it can transform your way of thinking about runtime configuration and object lifecycle management, and promotes a more flexible mindset.

That said, I absolutely despise autowiring and annotation-based DI...

Re:Dependency Injection is Evil (2011) by silon5 on Sunday April 12, 2015 @12:21PM (#9363804)
Strongly agreed especially with your last sentence.
Re:Dependency Injection is Evil (2011) by nulltype on Sunday April 12, 2015 @11:23AM (#9363618)
Could you provide a concrete example of a good use of DI?
Re:Dependency Injection is Evil (2011) by sk5t on Monday April 13, 2015 @10:26AM (#9367782)
In Java-land, let's say you have a class that depends on a micro-ORM library (or just a database connection, or whatever); the micro-ORM depends on a database connection, which might be yielded by a datasource, which in turn might be wrapped by a bounded connection pool.

DI lets you push all that stuff to configuration rather than wiring it up in code; it reduces drag during development because you can always say, ah, I don't need to think about how or where the micro-ORM boots up, I can tune it later... I can even share the connection pool across five different consumers that are not aware of each other and share no compile-time dependency.