Guice Binder 具有绑定功能
Guice Binder hasBind functionality
有什么方法可以检查接口的实现是否存在?
例如下面的方法"hasBind"不存在:
public class MyModule extends AbstractModule {
@Override
protected void configure() {
// do something like this:
if (!hasBind(SomeInterface.class)) {
bind(SomeInterface.class).to(MyOtherSomeInterface.class);
}
}
}
由于应用模块的顺序在 guice 中无关紧要,因此在创建注入器之前无法检测是否存在绑定,请参阅 this post。
建议的解决方案是创建一个具有默认绑定的起始模块,并使用 Modules.overwrite
应用您的附加绑定。
有什么方法可以检查接口的实现是否存在?
例如下面的方法"hasBind"不存在:
public class MyModule extends AbstractModule {
@Override
protected void configure() {
// do something like this:
if (!hasBind(SomeInterface.class)) {
bind(SomeInterface.class).to(MyOtherSomeInterface.class);
}
}
}
由于应用模块的顺序在 guice 中无关紧要,因此在创建注入器之前无法检测是否存在绑定,请参阅 this post。
建议的解决方案是创建一个具有默认绑定的起始模块,并使用 Modules.overwrite
应用您的附加绑定。