More Guice Please!!!: Re-Learning Google's Agile Lightweight Dependency Injection Library (Part 1.1)
Google Guice is used as a lightweight dependency injection framework that further assists developers in modularizing their applications. Google shared this very useful library with the development community in 2010 in between the Java SE 6 and Java SE 7 releases. This library is used in some of Java’s (and now Scala’s) most prominent libraries and platforms such as the Simian Army platform shared by Netflix.
We will begin our discussion of Google Guice with its Module interface. In the Guice developers’ own words, ‘A Guice-based application is ultimately composed of little more than a set of modules and some bootstrapping code.’ We will not be using this interface directly, but it gives us a very good context from which to start. Instead, we will be extending the abstract class that implements it -- intuitively named AbstractModule.
If you ever get a chance to look at the Module interface JavaDoc or source code, you’ll see a configure method taking a parameter of type Binder.
Listing 1.1: Google Guice’s Module interface
void configure(Binder binder) ;
We have plenty of time to talk about the Binder interface. For now, we’ll just take notice of the power and simplicity of the Google Guice library.