我想用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。
你知道我做错了什么吗?
发布于 2008-12-30 21:37:58
在第一个示例中,您通过Spring.NET检索对象。这意味着它将查找所有的依赖项,并将它们放入您的对象中,一切都会正常工作。
在第二个示例中,您始终忘记了Spring.NET,只创建了一个类的普通实例。
您在其中注册活页夹的行应该如下所示:
System.Web.Mvc.ModelBinders.Binders[typeof(App.Shared.DO.Gig)] = context.GetObject("GigModelBinder");其中,context是来自Spring.NET包的IApplicationContext或IObjectFactory实例。
祝你好运,马蒂亚斯。
https://stackoverflow.com/questions/400225
复制相似问题