2011-04-10

Let's Code Dimdwarf #47: Manual DI vs. Guice

The spike for manual dependency injection configuration is nearing its end and it's a good time to compare it with the original Guice-specific code which was needed to do the same thing. The infrastructure code is 50 lines of Scala for manual DI, vs. over 120 lines of Java code for Guice-based DI (which also includes lots of complex reflection). There is slightly more configuration code with manual DI, but it's also more explicit and it's easier to find out what is happening.

After this episode I did still some more refactoring off-camera, in order to reduce the duplication/boilerplate. Specifically, I created an abstract base class for the modules and passed the ServerBuilder instance to them as a hidden parameter (via a ThreadLocal), in addition to which I resolved the contention between ControllerHub and regular actors. The final code is here.

Download as MP4

Episode Archive