Skip to content

Adding bindings to multibinder from multiple private modules #906

@mmadson

Description

@mmadson

It looks like this is a known limitation and I was looking for an outstanding issue to see if work was being done to try and address it. I'd like to be able to do the following:

public final class MyAppModule extends AbstractModule {
    @Override
    protected void configure() {
        install(new FooPrivateModule());
        install(new BarPrivateModule());
    }
}

public final class FooPrivateModule extends PrivateModule {
    @Override
    protected void configure() {
        Multibinder<Thing> thingBinder = Multibinder.newSetBinder(binder(), Thing.class);
        thingBinder.addBinding().to(FooThing.class);
        expose(new TypeLiteral<Set<Thing>>() {});
    }
}

public final class BarPrivateModule extends PrivateModule {
    @Override
    protected void configure() {
        Multibinder<Thing> thingBinder = Multibinder.newSetBinder(binder(), Thing.class);
        thingBinder.addBinding().to(BarThing.class);
        expose(new TypeLiteral<Set<Thing>>() {});
    }
}

Set<Thing> things = Guice.createInjector(new MyAppModule()).getInstance(Key.get(new TypeLiteral<Set<Thing>>() {}));

// things would contain FooThing bound and exposed in FooPrivateModule and BarThing bound and exposed in BarPrivateModule

Thanks!

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