On Jul 21, 10:07 pm, "Rodrigo Couto" <
rco...@gmail.com> wrote:
> My code base is fraught with a recurring problem: I need to inject nested
> parameterized types
Today Guice has no way to inject the field
because it doesn't know what 'T' is:
@Inject private AlsoInjected<T> also;
Over the weekend I wrote some code that
moves us closer to this - we now have an API
that can reasonably resolve 'AlsoInjected<T>'
to 'AlsoInjected<String>' in your example:
http://publicobject.com/2008/07/typeresolver-tells-you-what-listget.html
The difficult part will be changing Guice so that
TypeResolver is used without breaking the
existing code that uses Guice.
Unfortunately, it seems that there's a lot of complexity
and nuance to getting this right, and I doubt we'll
have time to get it right before v 2.0, which we're
intending to release this summer.
I would definitely like this to work in one of the
follow-up releases, and it's a use case that's come
up a few times before.
As a work-around, you can create (gross) subtypes
for each injected type that makes the injected type
concrete. This will only work for constructor injection:
public static class StringInjectedImpl
extends InjectedImpl<String> {
@Inject
public StringInjectedImpl(AlsoInjected<String> alsoInjected) {
super(alsoInjected);
}
}
This solution is lame, but it should work. The other
solution is to create a factory by-hand that calls your
constructor.