Tag Archives: java

Stop abusing spring….please :)

Dependency Injection is magic.  Once you understand the trick, it is insanely simple.

Let’s all agree that if we are going to use dependency injection, we will first learn the trick.  It keeps the magic alive.

I highly recommend studying the Guice framework tutorials before you try to jump into spring (you may even decide to just use Guice instead).

To summarize using an excellent analogy from the people behind Guice, dependency injection is like the “Hollywood principle,” which is “don’t call us, we’ll call you.”  Think of it as a way to decouple your code such that testing small portions becomes trivial.  Certainly other ways to achieve the same means, but dependency injection does a lot of the work for you by using a simple annotation (in spring think  @autowired, in Guice think @Inject ).