-
Notifications
You must be signed in to change notification settings - Fork 9
Open
Description
I understand that binding multiple instances of the same type is a guice limitation and I need to use types to achieve this but I can't seem to find a combination that works.
This is what I typically do
public class ExportCompositeTransformer {
@Inject
private Export<IdentifierTransformer> permissionLookupExport;
}
...configure()...
bind(ExportCompositeTransformer.class).asEagerSingleton();
bind(export(IdentifierTransformer.class)).toProvider(service(CompositeTransformer.class)
.attributes(names("uri-part=searches.search-id"))
.export());
but I have a bundle that wants to expose two different transformers. I have tried
@Singleton
@Named("composite")
public class ExportCompositeTransformer ...
...configure()...
bind(ExportCompositeTransformer.class).annotatedWith(Names.named("composite")).asEagerSingleton();
bind(export(IdentifierTransformer.class)).annotatedWith(Names.named("composite")).toProvider(service(CompositeTransformer.class)
.attributes(names("uri-part=searches.search-id"))
.export());
As well as
...configure()...
bind(new TypeLiteral<Export<IdentifierTransformer>>() { });
bind(export(IdentifierTransformer.class)).annotatedWith(Names.named("composite")).toProvider(service(CompositeTransformer.class)
.attributes(names("uri-part=searches.search-id"))
.export());
In most cases I fail with an error No implementation for ExportCompositeTransformer annotated with @com.google.inject.name.Named(value=composite) was bound.
Any other ideas how I can create multiple Export bindings?
Metadata
Metadata
Assignees
Labels
No labels