Skip to main content

Posts

Showing posts from October, 2012

Google Guice: Dependency Injection with Guice 3.0

Guice (pronounced 'juice') is a lightweight dependency injection framework for Java 5 and above, from Google.

Why Google Guice?
Mature Framework – Used in many open source projects like apache struts, apache shindigetc. Google is using it in many mission critical applications. Simple and easy to use – It help in design better application. JSR 330 supportAOP support Very light weight – less then 1 MB in size Won the 18th Jolt Award  - for best Library, Framework, or Component.
Google Guice with example
Lets consider very high level application design where need services, persistence layer and authentication mechanism. Each of the functionality is very different but very dependent on each other. If we start writing the code without giving much thought on design, then we will be ending with the code, which is very tightly couple, hard to change and even harder to test.


Application design
Application main class
public class Application { private final AppService service; private f…