Google Guice – Agile Lightweight Dependency Injection Framework
This is a book review post. Apress presented me with the opportunity to review one of their books, and I opted for Google Guice – Agile Lightweight Dependency Injection Framework by Robbie Vanbrabrant, as I could learn something about Guice in the process. And learned something I did.
General Stuff
I read the e-book version (pdf), so I cannot tell you anything about the quality of the book itself. As a little side note, I find e-books harder to read, maybe because I cannot (easily) take it with me to the toilet.
The overall tone in the book is to the point and a bit fun. If you do not like a little joke or a funny way to express something, you might get a little irritated. On the other hand, it is not as if it destroys the meaning, and it is actually funny. At least I liked it!
The book is very much to the point, which I like, as it helps me get faster to the real stuff. There is so much to catch up on in the programming world, so no need to read a lot of unneccessary bullshit. To the point. Nice. The book does not provide much explanation of basic Java stuff. Good, but know your Java and Java5 workings, before going with this book.
When the book describes something that can be done in more than one way, there is always good advice on when to use which and why. This is exactly the kind of information I like to get out of a book. Not just a publication of the API, but in-depth advice on how to use the api and how not to (or what the implications are for doing it the way you do).
There are good spin-offs from reading this book. There are links to people who elaborate on ideas introduced (or mainstreamed) in guice. For instance, this was my first entry into TypeLiterals (or TypeReferences). Also, I got a pointer (again) to ServiceLoader in Java6, which we all need to know about.
Chapter by Chapter
Here, I will give you my opinion on each chapter.
Chapter 1: Setting the Stage
- A good and short introduction to dependency injection
- I was pleased that the intro on DI was nice and short. If you new nothing at all about DI, there could have been a little more info on this, but it gets the point out.
Chapter 2+3
A good introduction and explanation of the core Guice functionality – aka: how all the injection stuff works
- Know your Java(5) beforehand
- You will learn how to bootstrap guice, use guice annotations to inject stuff and how to wire it up with modules or annotations
- All other sorts and stuff like: Injecting properties, static injection, custom scopes, using web scopes, organizing bootstrapping into several modules, …
Chapter 4: AOP
- Guice supports method interception only (80% of the use cases in AOP are using 20% of the AOP features possible in Java)
- Guice uses aopalliance.jar, which makes for a common api to AOP from the framework (aka: You can reuse the spring tx interceptor, if you like)
- Shows how simple AOP can actually be, when packaged correctly
- Of course, this is also due to limiting in functionality provided, just like EJB3 does
Chapter 5: Integration with the Web
- How to bootstrap guice in a web application (the usual context listener stuff)
- How to inject on servlets, plugin for struts2, wicket
- I learned that guice 1.0 is very basic in its support for web integration
- I also learned, that warp provides extra stuff for web integration (amongst others)
- You will have to do some initial digging, to see how well guice integration is supported for your favourite web framework
Chapter 6: Practical Guice
- A practical example of how to configure guice with struts2, warp persist, JPA, and hibernate to build a real world web-stack application with transactions and database access
- Really good, binds all the previous theory together in a practical example
Chapter 7: Guice Recipes
- “..best practices and commonly asked questions”
- Interesting stuff, that you are sure to be interested in, if you plan on using guice for real
Chapter 8: The Future
- A look into what coming versions of guice might bring
Conclusion
Overall, I think the book is good and certainly worth the money. Two questions that I would expect any book on google guice to answer are:
- Why use guide instead of spring? and
- What about the services provided by spring – like transactions?
And I got an answer for these questions by reading this book:
- The last part of chapter 2, “Debunking Myths”, answers this in a good way. There is definitely a room for both Spring and Guice. They are not the same, even though they overlap. Guice is “just” a DI framework. In addition to this there are some other good points on their differences, and why you might chose one over the other.
- Go warp@wideplay
In addition to this, here is some cool stuff about guice, that I learned from reading the book:
- The way that all things are done in “plain” Java code (some of the config is not that plain, namely TypeLiterals). With a good IDE, this can safe you lots of building/running. Though IDEA has good support for spring, it has excellent support for Java.
- Guice supports circular dependencies (for all bindings, that bind to an interface)
August 6, 2008
Tags: book, guice, review Posted in: Programming

Leave a Reply