On Wed, Mar 3, 2010 at 8:29 PM, infinity2heaven <[email protected]>wrote:

> Thanks Eelco, I figured the anonymous inner class accessing an object
> reference, and while fixing it, your suggestion of using
> requestStaticInjection solves my problem.
>
> Dhanji:
> I still don't understand how autowire is "by default" in Guice. In the
> example I mentioned, I have to create n modules for each Class
> referencing template variable. Agreed, the following code
>
> new AbstractModule() {
>        @Override
>        public void configure() {
>                 requestStaticInjection (this);
> }});
>
> would inject the reference in the static instance, but that means I
> have to write the same boilerplate code for every test, ie, every
> class that has @Inject Template template.
>

It will work for non-static members, with just @Inject. Static injection is
not really intended to be used except in very rare cases like serialization.

The thing you need a module for is to couple interfaces to implementations
so Guice can tell which implementation to use when you refer to Template
(assuming it is an interface), for example XmlTemplate or HtmlTemplate. And
if you use @ImplementedBy on the interface, you don't need modules at all.

Dhanji.

-- 
You received this message because you are subscribed to the Google Groups 
"google-guice" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/google-guice?hl=en.

Reply via email to