In Guice, if you want to bind to a Provider, you should use the *toProvider*(..) methods. However, keep in mind that Guice will allow you to inject a Provider<T> of something even if it was bound using to(..). MapBinder specifically allows you to inject a Map<K, Provider<T>>, even if all the mapbindings were added using mapBinder.addBinding(K).to(T.class).
To Guice, injecting Provider<T> is effectively the same as injecting T directly, except that Guice won't attempt to construct the T until you call provider.get() (which is your requirement: making construction happen lazily). sam On Tue, Nov 29, 2011 at 8:18 AM, Xanadu <[email protected]> wrote: > hey ! > > I have several implementations for one interface. So I'm using > mapbinder to get one implementation for one string key. I need those > implementations to be constructed lazily : that's why I decided to use > provider for each implementation. > > My problem is that I have the following error : > "Binding to Provider is not allowed" > > Is this normal and do you know any workaround ? > > Thanks. > > -- > 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. > > -- 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.
