【发布时间】:2017-04-12 12:55:05
【问题描述】:
我一直在学习 Guice。我看到有一个按需注入here。
我想知道它的用途和一些例子。我有一个场景,我从 conf 文件中读取一组属性。那里没有注射。稍后我想将这些属性中的配置类的相同实例注入到其他类中。
class Props {
//set of properties read from a config file to this class
}
Props props = readProperties(); // instance of this class having all the properties but not put into injection container
稍后在连接类中我想使用它的注入
@Inject
public Connection(Props props) {
this.props = props;
}
在这种情况下是否可以使用 Guice 的按需注入?我也在使用 Play 框架的 conf 文件来加载我的模块文件。 play.modules.enabled += com.example.mymodule
【问题讨论】:
标签: java-8 guice playframework-2.5