我正在使用实现ASP.NET MembershipProvider的MVC AccountController。 我有一个所有数据库访问的存储库,其中我添加了一个返回国家/地区列表的国家/地区属性。我想将国家下拉列表添加到注册页面,因此我需要能够从我的存储库获取这些数据并将其传递给View。 我一直在我的其他控制器中使用构造器注入,但我不知道如何将其应用于现有的AccountController。通过构造函数访问AccountController中的存储库
// This constructor is used by the MVC framework to instantiate the controller using
// the default forms authentication and membership providers.
public AccountController()
: this(null, null)
{
}
// This constructor is not used by the MVC framework but is instead provided for ease
// of unit testing this type. See the comments at the end of this file for more
// information.
public AccountController(IFormsAuthentication formsAuth, IMembershipService service)
{
FormsAuth = formsAuth ?? new FormsAuthenticationService();
MembershipService = service ?? new AccountMembershipService();
}
我可以更改现有的AccountController构造函数来访问我的存储库吗?
我可以推荐使用Windsor,因为它很好地实现了*组件负担*。 – Henrik 2011-03-05 19:19:23