Java dependency injection just got better: Google Guice 2.0 has been released.
What's new:
- Provider methods. You can now annotate methods in your
Moduleso you avoid manually constructing dependencies. - Binding overrides. One
Modulecan now override the bindings in another. - Private modules. You can now create bindings that are not externally visible, in order to encapsulate your dependency injections.
- The ability to inject members of sets and maps using
MultibinderandMapBinderrespectively. ServletModulenow provides programmatic configuration of servlets and filters.GuiceServletContextListenercan be used to help bootstrap a Guice application in a servlet container.- Custom injections. Guice now includes hooks that allow other frameworks to define custom injection annotations. This enables Guice to host other frameworks that have their own injection semantics or annotations.
- A tree-like structure for
Injectors, i.e., anInjectorcan have children that inherit all of its bindings. - An introspection API: like reflection but for Guice bindings.
- Pluggable type converters that convert constant string bindings to other types, i.e., Dates, URLs, etc.
- OSGi compatible. Guice now works well in OSGi managed environments, because AOP-generated classes use a bridge classloader.
- AOP is now optional, so Guice will work on platforms that don't support bytecode generation (Android).
You can download the new release here. The new manual is here. Now all they have to do is update the public Maven repository.
javax.inject.Inject
On related news (Crazy) Bob Lee, the creator of Guice, and Rod Johnson, the creator of Spring, have gotten together to propose a standard set of annotations and interfaces for using dependency injection in Java under the banner of JSR-330: Dependency Injection for Java (still only a proposal, so JSR-330 is a tentative moniker). There is also a corresponding project over at Google Code. The standardization should greatly help the use of dependency injection in shared 3rd party libraries, allowing the application developer to avoid having to initialize more than one dependency injection framework.
These annotations are modelled closely on those currently in Google Guice:
- @Inject - Identifies injectable constructors, methods, and fields
- @Qualifier - Identifies qualifier annotations
- @Scope - Identifies scope annotations
- @Named - String-based qualifier
- @Singleton - Identifies a type that the injector only instantiates once
The utility interface Provider is also in the proposed specification.
Delicious
Digg
StumbleUpon
Propeller
Reddit
Magnoliacom
Newsvine
Furl
Facebook
Google
Yahoo
Technorati
Icerocket
Recent comments
15 weeks 4 days ago
16 weeks 5 days ago
17 weeks 2 days ago
17 weeks 2 days ago
17 weeks 6 days ago
17 weeks 6 days ago
28 weeks 6 days ago
29 weeks 5 days ago
32 weeks 7 hours ago
33 weeks 2 days ago