这更像是一个概念性问题。何时使用模型绑定(在ASP.NET MVC框架中)以及何时使用IoC注入对象(可以说Autofac在这里)?依赖注入与模型绑定(ASP MVC,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/
是的马修,真的有道理,但我发现在下面的链接更好的解决方案。我们可以实现我们自己的Model Binder并从其中获取用户对象的回购。我发现它更符合模型绑定概念。 > http://buildstarted.com/2010/09/12/custom-model-binders-in-mvc-3-with-imodelbinder/。 – neebz 2010-11-22 03:17:08