【发布时间】:2011-02-25 10:57:54
【问题描述】:
我了解使用构造函数注入优于 setter 注入的好处,但在某些情况下,我必须坚持仅使用基于 setter 的注入。
我的问题是如何使用 injector.injectMembers() 方法注入所有基于 setter 的注入类的成员?
//I am calling this method in init method of my application
private static final Injector injector = Guice.createInjector(new A(), new B());
//Injecting dependencies using setters of all classes bound in modules A and B
injector.injectAllMembers()??
【问题讨论】:
-
你能给出一个特定用例的代码示例吗?
-
Guice 已经做到了。你真的有问题吗?
标签: guice