Reputation: 5875
I have two Guice modules that each do an @Provides on the same interface. Each runs independently just fine.
Now I have a 3rd module that wants to bring in both of those. I want that 3rd module's @Provides to trump the others, which seems ideal for Modules.override. Indeed, this works.
Modules.override(childModule1).with(parent);
The parent trumps the child's binding. Great!
This, however, fails :(.
Modules.override(childModule1, childModule2).with(parent);
In that case, it complains that a binding to Foo was "already bound" by the childModule2. Looks like override only works if there's one submodule doing the providing. Is there something I've missed to make this work?
Upvotes: 0
Views: 2696
Reputation: 5875
I figured out a solution, though it seems firmly in the hack category. I had to nest the overides.
Modules.override(Modules.override(childModule1).with(childModule2)).with(parent);
Upvotes: 2