Guice, Google's internal Java dependency injection framework, released as
open source
Posted by
Dion Almaer, Google Developer ProgramsGoogle has been
using a blazingly fast, innovative, Java 5-based dependency injection framework in mission
critical applications for quite some time.
The project is lead by Bob
Lee, and we are pleased to say that we have
released it to the community as
open source software.
Guice wholly embraces annotations
and generics, thereby enabling you to wire together and test objects with less effort than
ever before. Annotations finally free you from error-prone, refactoring-adverse string
identifiers.
Guice injects constructors, fields and methods (any
methods with any number of arguments, not just setters). Guice includes advanced features such
as custom scopes, circular dependencies, static member injection, Spring integration, and AOP
Alliance method interception, most of which you can ignore until you need it.
Guice already has a community around it, and already powers Struts 2's plugin
architecture.
We asked Bob Lee a few questions about the project:
Why was Guice created?We
created Guice hoping to write less code and break up a multi-million line app. We looked at
existing solutions, but we saw a lot of doors opened by the new Java 5 features. When I
started from scratch I followed a use case driven approach and built a real application. As I
wrote I was constantly asking myself "how do I really want to be writing this?".
I value pragmatism and followed Josh Bloch's API design advice, especially,
"when in doubt, leave it out."
Finally, we strove most of all for
maintainability. Can a new programmer sit down at a million line code base and maintain it? We
think type safety is a huge factor here.
Who should use
Guice?Anyone writing Java code. We see Guice as a
lighter weight alternative to the factory pattern.
More
information: