新しい Play 2.0 プロジェクトがあり、複雑なサードパーティ統合コードを追加する際に DI を導入する予定です。
Play 2.0 用の Guice プラグインがありますが、2.1 で廃止されるようで、2.1 はそれほど遠くないという予感があります。
https://github.com/typesafehub/play-plugins/tree/master/guice
Guice は Play 2.0/2.1 の安全な賭けですか、それとも他のオプションを検討する必要がありますか?
新しい Play 2.0 プロジェクトがあり、複雑なサードパーティ統合コードを追加する際に DI を導入する予定です。
Play 2.0 用の Guice プラグインがありますが、2.1 で廃止されるようで、2.1 はそれほど遠くないという予感があります。
https://github.com/typesafehub/play-plugins/tree/master/guice
Guice は Play 2.0/2.1 の安全な賭けですか、それとも他のオプションを検討する必要がありますか?
2.1バージョンと、Globalオブジェクトからの新しいコントローラーインスタンス化を使用します。
これがドキュメントからのGuiceの例です:
import play.GlobalSettings;
import com.google.inject.Guice;
import com.google.inject.Injector;
public class Global extends GlobalSettings {
private static final Injector INJECTOR = createInjector();
@Override
public <A> A getControllerInstance(Class<A> controllerClass) throws Exception {
return INJECTOR.getInstance(controllerClass);
}
private static Injector createInjector() {
return Guice.createInjector();
}
}
これらのコントローラーの特別なルートを、特別なもので宣言する必要があります@。
GET /myUrl @controllers.MyController.myMethod()
また、Springを使用してこのデモを見ることができます:https ://github.com/guillaumebort/play20-spring-demo