我无法找到正确的 Unity 配置以使其与 MvcMembership 一起使用。
此时,我收到以下错误消息:
无法构造 Boolean 类型。您必须配置容器以提供此值。
这是我注册依赖项的代码:
container.RegisterInstance<MembershipProvider>(Membership.Provider);
container.RegisterType<IMembershipSettings,AspNetMembershipProviderSettingsWrapper>();
container.RegisterType<IUserService, AspNetMembershipProviderWrapper>();
container.RegisterType<IPasswordService, AspNetMembershipProviderWrapper>();
container.RegisterType<IRolesService, AspNetRoleProviderWrapper>();
container.RegisterType<ISmtpClient, SmtpClientProxy>();
container.RegisterType<IRegistrationSettings, RegistrationSettings>();
这是我的堆栈跟踪:
[InvalidOperationException:无法构造布尔类型。您必须配置容器以提供此值。] Microsoft.Practices.ObjectBuilder2.DynamicMethodConstructorStrategy.GuardTypeIsNonPrimitive(IBuilderContext context, SelectedConstructor selectedConstructor) +277 Microsoft.Practices.ObjectBuilder2.DynamicMethodConstructorStrategy.PreBuildUp(IBuilderContext context) +485 Microsoft.Practices.ObjectBuilder2。 StrategyChain.ExecuteBuildUp(IBuilderContext context) +434 Microsoft.Practices.ObjectBuilder2.DynamicMethodBuildPlanCreatorPolicy.CreatePlan(IBuilderContext context, NamedTypeBuildKey buildKey) +400 Microsoft.Practices.ObjectBuilder2.BuildPlanStrategy.PreBuildUp(IBuilderContext context) +222 Microsoft.Practices.ObjectBuilder2.StrategyChain。 ExecuteBuildUp(IBuilderContext 上下文)+434 Microsoft.Practices。
[ResolutionFailedException:依赖项解析失败,类型=“MyProject.Web.Areas.MvcMembership.Controllers.UserAdministrationController”,名称=“(无)”。异常发生时:解决时。
例外是: InvalidOperationException - 无法构造 Boolean 类型。您必须配置容器以提供此值。
在异常发生时,容器是:
解析 MyProject.Web.Areas.MvcMembership.Controllers.UserAdministrationController,(none) 解析构造函数 MyProject.Web.Areas.MvcMembership.Controllers.UserAdministrationController 的参数“membershipSettings”(MvcMembership.Settings.IMembershipSettingsmembershipSettings, MvcMembership.IUserService userService, MvcMembership.IPasswordService passwordService, MvcMembership.IRolesService rolesService, MvcMembership.ISmtpClient smtpClient) Resolving MvcMembership.Settings.AspNetMembershipProviderSettingsWrapper,(none) (映射自 MvcMembership.Settings.IMembershipSettings, (none)) 解析参数“注册”的构造函数 MvcMembership.Settings.AspNetMembershipProviderSettingsWrapper(MvcMembership Settings.IRegistrationSettings 注册,MvcMembership.Settings.IPasswordSettings 密码,MvcMembership.Settings.ILoginSettings login) Resolving MvcMembership.Settings.RegistrationSettings,(none) (映射自 MvcMembership.Settings.IRegistrationSettings,(none)) 解析构造函数的参数“requiresUniqueEmailAddress” MvcMembership.Settings.RegistrationSettings(System.Boolean requiresUniqueEmailAddress) 解析系统.Boolean,(none) ] Microsoft.Practices.Unity.UnityContainer.DoBuildUp(类型 t,对象存在,字符串名称,IEnumerable布尔值,(无)] Microsoft.Practices.Unity.UnityContainer.DoBuildUp(类型 t,现有对象,字符串名称,IEnumerable布尔值,(无)] Microsoft.Practices.Unity.UnityContainer.DoBuildUp(类型 t,现有对象,字符串名称,IEnumerable1 resolverOverrides) +546
Microsoft.Practices.Unity.UnityContainer.DoBuildUp(Type t, String name, IEnumerable
1 resolverOverrides) +20 System.Web.Mvc.DefaultControllerActivator.Create(RequestContext requestContext, Type controllerType) +68
[InvalidOperationException:尝试创建类型为“MyProject.Web.Areas.MvcMembership.Controllers.UserAdministrationController”的控制器时发生错误。确保控制器有一个无参数的公共构造函数。] System.Web.Mvc.DefaultControllerActivator.Create(RequestContext requestContext, Type controllerType) +634403 System.Web.Mvc.DefaultControllerFactory.CreateController(RequestContext requestContext, String controllerName) +93 System. Web.Mvc.MvcHandler.ProcessRequestInit(HttpContextBase httpContext, IController& controller, IControllerFactory& factory) +346 System.Web.Mvc.<>c_ DisplayClass6.b _2() +71 System.Web.Mvc.<>c__DisplayClassb1.<ProcessInApplicationTrust>b__a() +19
System.Web.Mvc.SecurityUtil.ProcessInApplicationTrust(Func
1 func) +161 System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +405 System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +375