Regretfully, multibindings cannot span injectors and therefore they
cannot span private modules. This sucks! But there's a (lame)
workaround. Expose a key in the private module, and multibind it in a
regular module:
Injector injector = Guice.createInjector(
new PrivateModule() {
public void configure() {
bind(Key.get(Source.class, named("one"))).to
(SourceImpl.class);
expose(Key.get(Source.class, named("one")));
...
}
},
new PrivateModule() {
public void configure() {
bind(Key.get(Source.class, named("two"))).to
(SourceImpl.class);
expose(Key.get(Source.class, named("two")));
...
}
},
new Module() {
public void configure() {
Multibinder<Source> multibinder
= Multibinder.newSetBinder(binder(), Source.class);
multibinder.addBinding().to(Key.get(Source.class, named
("one")));
multibinder.addBinding().to(Key.get(Source.class, named
("two")));
}
});