【发布时间】:2013-11-21 14:17:15
【问题描述】:
在 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());
这会导致 HK2 在需要创建 FooInterface 时调用构造函数 FooImpl()。
如果 FooImpl 没有构造函数怎么办?
- 如果打算使用静态工厂方法
FooImpl.getInstance()进行实例化怎么办? - 如果它打算被工厂对象实例化怎么办
fooFactory.create()
我看到ResourceConfig 有一个方法bind(FactoryDescriptors factoryDescriptors),但我不清楚构建FactoryDescriptors 对象的习语是什么,并且无法在网上找到任何示例。
【问题讨论】:
标签: java dependency-injection hk2