Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Binding Multiple Exports #83

Open
set321go opened this issue Feb 12, 2016 · 0 comments
Open

Binding Multiple Exports #83

set321go opened this issue Feb 12, 2016 · 0 comments

Comments

@set321go
Copy link

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant