我将 StructureMap 用于 IoC,它适用于常规控制器,但我无法使其与区域一起使用。我AccountController
在管理区有以下内容:
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"]);