Hi,

I am currently trying to bind Provider<T> to some instance of 
CustomProvider<T> (where T is a more complex, generic type).
But I get "Binding to Provider is not allowed" when I create the Injector.

Although my code is much more complex (I have a generic helper method 
that can do the following for any T type, not just Icon as in the 
example below), I think it boils down to the following:

binder().bind(new 
TypeLiteral<Provider<ResourceConverter<Icon>>>(){}).toInstance(new 
ConverterProvider<Icon>(Icon.class));

where:

class ConverterProvider<T> implements Provider<ResourceConverter<T>>
{
    ConverterProvider(TypeLiteral<T> type) {...}
    public ResourceConverter<T> get() {...}
}

I don't really understand why Guice doesn't allow binding to a Provider? 
Actually I don't bind TO a provider, but I bind A provider TO an 
instance of that type (ie Provider...)! That's not exactly the same!

Actually, the reason why I do that is that I don't want to make it 
possible users of my library to directly inject ResourceConverter<T> 
into a class, but exclusively Provider<ResourceConverter<T>>; isn't that 
possible with Guice?

If not, that's not a real blocking problem, it would just make my API a 
bit weaker than it has to (aand then I'll have to put more emphasis on 
the javadoc;-))

Thanks in advance for any feedback

Jean-Francois

--~--~---------~--~----~------------~-------~--~----~
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