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?
[ Parent
| on HN ]
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.