我正在使用StructureMap for IoC,它對於常規控制器工作正常,但我無法使它適用於區域。我有以下AccountController
在管理區:在ASP.NET MVC區域中使用StructureMap
public class AccountController : Controller
{
private readonly IFormsAuthenticationService formsService;
private readonly IMembershipService membershipService;
public AccountController(IFormsAuthenticationService formsService, IMembershipService membershipService)
{
this.formsService = formsService;
this.membershipService = membershipService;
}
...
}
而這裏的錯誤:
System.InvalidOperationException: An error occurred when trying to create a controller of type 'Foo.Areas.Administration.Controllers.AccountController'. Make sure that the controller has a parameterless public constructor. ---> System.MissingMethodException: No parameterless constructor defined for this object.
任何幫助將不勝感激!
編輯
StructureMap
解決不了MembershipProvider
。
這裏的解決方案:
For<MembershipProvider>().Use(Membership.Providers["AspNetSqlMembershipProvider"]);