1

モデル バインダーを Nhibernate で構成したい:

ので、私は持っています:

<object id="GigModelBinder" type="App.ModelBinders.GigModelBinder, App.Web"  singleton="false"  >
<property name="VenueManager" ref="VenueManager"/>
<property name="ArtistManager" ref="ArtistManager"/>

コントローラーのアクションをマークして、正しいモデル バインダーを使用する属性があります。

[AcceptVerbs("POST")]
    public ActionResult Create([GigBinderAttribute]Gig gig)
    {
        GigManager.Save(gig);
        return View();
    }

これは正常に動作し、私の GigModelBinder には正しい VenueManger と ArtistManager が注入されています

ただし、アプリケーションの開始時に追加する場合:

System.Web.Mvc.ModelBinders.Binders.Add(typeof(App.Shared.DO.Gig), new GigModelBinder());

コントローラーアクションでは、次を使用します。

UpdateModel<Gig>(gig);

例えば:

[AcceptVerbs("POST")]
    public ActionResult Update(Guid id, FormCollection formCollection)
    {
        Gig gig = GigManager.GetByID(id);

        UpdateModel<Gig>(gig);

        GigManager.Save(gig);
        return View();
    }

VenueManger と ArtistManager は GigModelBinder に挿入されていません。

私が間違っていることはありますか?

4

1 に答える 1

1

最初の例では、Spring.NET 経由でオブジェクトを取得します。つまり、すべての依存関係を探してオブジェクトに貼り付け、すべてがうまく機能します。

2 番目の例では、Spring.NET のことをずっと忘れて、クラスの通常のインスタンスを作成するだけです。

バインダーを登録する行は次のようになります。


System.Web.Mvc.ModelBinders.Binders[typeof(App.Shared.DO.Gig)] = context.GetObject("GigModelBinder");

context は、Spring.NET パッケージの IApplicationContext または IObjectFactory インスタンスのいずれかです。

よろしく、マティアス。

于 2008-12-30T21:37:58.087 に答える