This is a cache of http://dbflute.seasar.org/ja/manual/reference/diway/guice/index.html. It is a snapshot of the page at 2024-03-19T00:41:44.627+0000.
<strong>google</strong> Guiceの取扱い | <strong>dbflute</strong>

google Guiceの取扱い

基本情報

対応バージョン
google Guice 1.0 or 2.0 (no-aop OK)

DI設定クラス (dbfluteModule)

dbfluteは、Generateタスクにて dbfluteのコンポーネントの登録処理が実装されている dbfluteModule を自動生成します。主には、Behavior と allcommon のクラスが登録されます。

この dbfluteModule が アプリケーションのDI設定ファイルから参照されるように設定 することで、アプリケーションのコンポーネントからdbfluteのコンポーネント(主にBehavior)が利用できるようになります。

e.g. dbfluteモジュールの初期化 @Java
List<Module> moduleList = ...
DataSource dataSource = ...
moduleList.add(new dbfluteModule(dataSource));
Injector injector = Guice.createInjector(moduleList.toArray(new Module[]{}));

DIの方法 (Behavior)

DI管理されているコンポーネントクラスにおいて、Behavior のプロパティを定義し、@Inject アノテーションを付与するとインジェクトされます。他にも方法はありますのでアプリケーションで統一的な実装をするようにして下さい。

e.g. Inject アノテーションの利用 {Pageクラス} @Java
public class XxxPage {
    protected MemberBhv memberBhv;

    @Inject
    public void setMemberBhv(MemberBhv memberBhv) {
        this.memberBhv = memberBhv;
    }
}

Exampleのススメ

google Guice を使ったExample実装 dbflute-guice-example があります。