Introducing @Guice annotation
You may already have heard about Seam being a “deep integration framework” and Google Guice providing lightweight dependency injection. The news is that you can now easily use Seam together with Guice.
The WebBeans specification is built upon concepts from both of those frameworks. Since Seam provides Spring support in the IoC module, why not to integrate Guice as well? Thinking this way I have implemented Guice support for Seam.
The rule is fairly simple – if you want to use Guice injection in your Seam component, annotate it with the @Guice annotation.
For all Seam components annotated with the @Guice annotation, Guice injection will be performed automatically.
Great, but wait… which Guice injector will be used? Well, the one you provide. Just edit components.xml:
myGuiceInjector should be a Seam component that implements the Injector interface.
You may want to create it from a list of modules:
Of course you can also use an injector that is already used in other, possibly non-Seam, parts of you application. That was one of the reasons I implemented this integration – to tie other parts of an application that used Guice together with Seam.
Give it a try!
I have included more information on the wiki page. You can download seam-guice library and browse the source code. It is implemented as a simple interceptor. Let me know if you find a bug or a place for improvement.