看起来您将需要跳过一些箍,以保证私有模块的绑定状态,以便它们可以在顶级注射器的多重绑定中使用。
这应该工作:
public class SquareModule extends AbstractModule { // does not extend PrivateModule @Overide public void configure() { // this key is unique; each module needs its own! final Key<MyInterface> keyToExpose = Key.get(MyInterface.class, Names.named("square")); install(new PrivateModule() { @Override public void configure() { // Your private bindings go here, including the binding for MyInterface. // You can install other modules here as well! ... // expose the MyInterface binding with the unique key bind(keyToExpose).to(MyInterface.class); expose(keyToExpose); } }); // add the exposed unique key to the multibinding Multibinder.newSetBinder(binder(), MyInterface.class).addBinding().to(keyToExpose); }}此解决方法是必需的,因为需要在顶级进样器处进行多重绑定。但是专用模块绑定对该注入器不可见,因此您需要公开它们。



