Gentlemen,

I would like to propose a small extension to the Binder and/or the
AbstractModule:
Consider these cases:

bind(Type.class).toInstance(new A(... some constant parameters...));

In this case Guice will inject members to the instance of A before
using it for injection.
All good.
However, sometimes I am using the following construct to quickly setup
some dependency chains (e.g. for tests):
bind(Type.class).toInstance(new A(new B(... some constant
parameters...)));

In this case Guice will again inject members to the instance of A but
NOT to the instance of B (because Guice doesn't know anything about
B).
This is where the new requestInjection() facility comes in really
handy.
However, I have to resort to something rather lengthy like this in
order to get the job done:

B b = new B(... some constant parameters...);
requestInjection(b);
bind(Type.class).toInstance(new A(b));

Now I would prefer to shorten this to:

bind(Type.class).toInstance(new A(injected(new B(... some constant
parameters...))));

which is easy with the following helper method (which I am currently
using in my extension to AbstractModule):

protected <T> T injected(T object) {
    requestInjection(object);
    return object;
}

Wouldn't this be a sensible extension which should be in the Binder by
default?

Thanks for a great addition to the java world!

Cheers,
Mathias
--~--~---------~--~----~------------~-------~--~----~
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