【发布时间】:2010-11-21 20:09:26
【问题描述】:
这更像是一个概念问题。何时使用模型绑定(在 ASP.NET MVC 框架中)以及何时使用 IoC 注入对象(这里说 Autofac)?
一个特定的场景就像让我们说,我有以下操作方法
public ActionResult EditProfile(string UserId)
{
// get user object from repository using the the UserId
// edit profile
// save changes
// return feedback
}
在上述场景中,是否可以将用户对象注入到操作方法中,以便使用 UserId 自动获取用户对象?结果签名为:
public ActionResult EditProfile(UserProfile userObj) //userObj injected *somehow* to automatically retreive the object from repo using UserId ?
对不起,如果这一切都没有意义。这是我第一次使用 IoC。
编辑:
这是这样做的方法> http://buildstarted.com/2010/09/12/custom-model-binders-in-mvc-3-with-imodelbinder/
【问题讨论】:
标签: asp.net-mvc-2 ioc-container autofac model-binding