Google Guiced

2009 May 19
by Joel

So yesterday I had some time to myself and got to studying Google Guice. I read the APress book, Google Guice: Agile Lightweight Dependency Injection Framework, by Robbie Vanbrabant. It was a surprisingly short book, at only 180 pages — I finished the whole thing in half a day! Now I don’t get how someone would rate the book less than four stars in Amazon, though; the book made a lot of sense to me, and anybody who couldn’t get it either isn’t smart enough or just didn’t read through it very well. If you just blindly typed in the examples, of course you’d encounter errors, because some of the examples weren’t complete to begin with for brevity’s sake. You’re supposed to figure it out yourself and fill in the missing pieces; the author only focused on the point he was discussing without getting bogged down with too much boilerplate code in the examples.

Anyway, you can tell I liked the book. It actually made sense to me, and I can see where Guice could do some things better than Spring. DI feels better in Guice than in Spring, even with Spring’s newer annotation support. Guice binding DSL is very, very elegant and easy to follow; its a far cry from XML configuration in Spring. And, while Spring seems to be okay with annotating private attributes, Guice best practices rightly discourages it, preferring method annotations instead, so that your classes would lend itself well to testing. AOP on Guice is way simpler than with Spring as well. Compared to Guice, Spring’s AOP support doesn’t seem so ‘agile’ anymore.

Man, that was some mighty tasty Google Kool-Aid I drank yesterday (no pun intended)! If you haven’t had that much invested into Spring yet, or are about to work on a new project fromt the ground up, I highly recommend you check out Google Guice and see what it could do for you!