在 HK2 中,配置注入的基本示例代码是这样的(在扩展的类中AbstractBinder:
bind(BuilderHelper
.link(FooImpl.class) // the class of the object to be injected
.to(FooInterface.class) // identifies what @Inject fields to link to
.build());
这会导致 HK2FooImpl()在需要创建FooInterface.
如果 FooImpl 没有构造函数怎么办?
- 如果打算用静态工厂方法实例化怎么办
FooImpl.getInstance() - 如果它打算由工厂对象实例化怎么办
fooFactory.create()
我看到ResourceConfig有一个方法bind(FactoryDescriptors factoryDescriptors),但我不清楚构建FactoryDescriptors对象的习语是什么,并且无法在网上找到任何示例。