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.
@Inject is a Guice annotation and I expect it to be smart to figure
out (autowire) the binding.
As I understand now, this is not the case.
On Mar 3, 1:02 am, Eelco Hillenius <[email protected]> wrote:
> > injector = Guice.createInjector(new
> > TemplateModule.Builder().withSession(new Session()).buildModule(),
> > new AbstractModule() {
> > �...@override
> > public void configure() {
> > requestInjection(this);
> > }});
>
> This doesn't work because requestInjection(this) requests injection of
> your anonymous module
> and because @BeforeClass can only be used on a static method, so there
> is no 'this' for your unit test.
>
> I think adding a method with @Before and then
> requestInjection(YourTest.this) should work. Or you could use
> requestStaticInjection instead. Or, what I would do frankly, don't
> bother and just get your instance from the injector when you need it.
>
> Eelco
--
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.