Am using guice 3.0 . Is there any other way of injecting a set of interface implementations as provider apart from upgrading since the one having it is still in beta ?
On Thursday, June 11, 2015 at 5:40:56 PM UTC+5:30, Suma Shivaprasad wrote: > > Trying to inject a collection of providers which implement an interface but > consistently getting issues with injection as below > > > No implementation for > java.util.Collection<com.google.inject.Provider<TypesChangeListener>> was > bound. > > [ERROR] at > com.google.inject.internal.Errors.throwCreationExceptionIfErrorsExist(Errors.java:435) > [ERROR] at > com.google.inject.internal.InternalInjectorCreator.initializeStatically(InternalInjectorCreator.java:154) > [ERROR] at > com.google.inject.internal.InternalInjectorCreator.build(InternalInjectorCreator.java:106) > > > > Module > > ======== > > Multibinder<TypesChangeListener> typesChangeListenerBinder = > Multibinder.newSetBinder(binder(), TypesChangeListener.class); > > typesChangeListenerBinder.addBinding().to(GraphBackedSearchIndexer.class); > > // bind the MetadataService interface to an implementation > > bind(MetadataService.class).to(DefaultMetadataService.class).asEagerSingleton(); > > > > Injected class > > ============== > > > @Inject > DefaultMetadataService(final B b, final C c, final > Collection<Provider<TypesChangeListener>> typeChangeListeners) > > > > GraphBackedSearchIndexer implements TypesChangeListener > > > > I see that Multibinder<TypesChangeListener> typesChangeListenerBinder = > Multibinder.newSetBinder(binder(), TypesChangeListener.class); > > > is actually resulting in Set<TypesChangeListener> rather than > Set<Provider<TypesChangeListener>> which is what I need? > > > The javadoc for MultiBinder - > http://google.github.io/guice/api-docs/latest/javadoc/index.html?com/google/inject/multibindings/Multibinder.html > says "Collection<Provider<T>> could also be injected" but does not provide > any examples. > > > Please let me know how this can be achieved. > > > > Thanks > Suma > > > -- You received this message because you are subscribed to the Google Groups "google-guice" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. Visit this group at http://groups.google.com/group/google-guice. To view this discussion on the web visit https://groups.google.com/d/msgid/google-guice/868bb5c5-590a-47b6-88de-4e90ebb9dcf2%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
