Skip to content

Binding Multiple Exports #83

@set321go

Description

@set321go

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

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions