【发布时间】:2014-12-22 09:54:32
【问题描述】:
我正在使用 Cloud 端点在 Google App Engine 平台上创建一个应用程序。我读到 Dagger 是谷歌应用引擎中 DI 的推荐方式,但它需要 Bootstrap Injection 来构建其对象图,该对象图可用于类似以下方式的注入:
class CoffeeApp implements Runnable {
@Inject CoffeeMaker coffeeMaker;
@Override public void run() {
coffeeMaker.brew();
}
public static void main(String[] args) {
ObjectGraph objectGraph = ObjectGraph.create(new DripCoffeeModule());
CoffeeApp coffeeApp = objectGraph.get(CoffeeApp.class);
...
}
}
这是因为
为了使用图表,我们需要引导注入。这个 通常需要注入命令行应用程序的主类,或者 Android 应用程序的活动类。在我们的咖啡示例中, CoffeeApp 类用于启动依赖注入。 (如匕首网站上所述)
我知道我需要在 ServletContextListener 中创建图表,但我没有得到注入应用程序“主类”的部分。
【问题讨论】:
标签: java google-app-engine dependency-injection google-cloud-endpoints dagger