Adding to Multibinder in child injector
guice, java
Solution
From what I've found, this isn't and can't be possible. If the set of objects is requested in the first injector, it has to be injected with the bindings from the first injector. If you then make a child injector and bind an additional value, you're effectively overriding the set binding from the parent injector, and Guice does not allow that.
Problem
I'm trying to combine the Guice functionalities of child injectors with Multibinders. For example: ``` public class Test { public static void main(String[] args) { Guice.createInjector(new FirstModule(), new SecondModule()); // works perfectly, returns set with 2 elements Guice.createInjector(new FirstModule()).createChildInjector(new SecondModule()); // fails: A binding to java.util.Set<Test$MyInterface> was already configured at Test$FirstModule.configure(Test.java:15). } private static class FirstModule extends AbstractModule { @Override protected void configure() { Multibinder.newSetBinder(binder(), MyInterface.class).addBinding().to(FirstImplementation.class); } } private static class SecondModule extends AbstractModule { @Override protected void configure() { Multibinder.newSetBinder(binder(), MyInterface.class).addBinding().to(SecondImplementation.class); } } private static interface MyInterface {} private static class FirstImplementation implements MyInterface {} private static class SecondImplementation implements MyInterface {} } ``` Is it possible to have a child injector add to a multibinding somehow?