Microsoft.AspNet.Identity.EntityFramework.UserStore没有采用参数的构造函数

时间:2018-07-02 05:15:30

标签: asp.net-mvc dependency-injection entity-framework-6 asp.net-identity unity-container

我是使用MVC5和EF 6开发应用程序的新手。我正在使用依赖项注入来解析我的类。一切正常,直到我更改了连接字符串并更改了我的依赖性注册类(统一配置)中的某些内容(我不知道)。

现在,每当我运行它时,都会出现此错误。 Microsoft.AspNet.Identity.EntityFramework.UserStore没有采用参数的构造函数。我正在使用Unity nuget包管理器

下面是我的代码,将不胜感激

    using Microsoft.AspNet.Identity;
    using Microsoft.AspNet.Identity.EntityFramework;
    using Oxford.Core.Data;
    using Oxford.Data;
    using Oxford.Services;
    using OxfordLibrary.Models;
    using System.Web.Mvc;
    using Unity;
    using Unity.Injection;

    namespace OxfordLibrary.App_Start
    {
        public class UnityConfig
        {
            public static void RegisterComponents()
            {
                // Repository
                var container = new UnityContainer();

                // register all your components with the container here
                // it is NOT necessary to register your controllers

                // e.g. container.RegisterType<ITestService, TestService>();
                container.RegisterType(typeof(IRepository<>), typeof(EfRepository<>));

                container.RegisterType<ApplicationUserManager>();


                // Services

                container.RegisterType<IMasterService, MasterService>();

                // Resolve

                container.RegisterType<IUserStore<ApplicationUser>, UserStore<ApplicationUser>>(
                       new InjectionConstructor(typeof(ApplicationDbContext)));
            }
        }
    }

OxfordLibrary是我的项目的名称 我得到的异常是: System.InvalidOperationException   HResult = 0x80131509   Message =类型Microsoft.AspNet.Identity.EntityFramework.UserStore`1 [[OxfordLibrary.Models.ApplicationUser,OxfordLibrary,Version = 1.0.0.0,Culture = neutral,PublicKeyToken = null]]没有采用参数的构造函数( ApplicationDbContext)。   来源= Unity.Abstractions   堆栈跟踪:    在Unity.Injection.InjectionConstructor.ConstructorByType(Type typeToCreate,Type []类型)    在Unity.Injection.InjectionConstructor.AddPolicies(类型serviceType,类型ImplementationType,字符串名称,IPolicyList策略)    在Unity.UnityContainer.RegisterType(类型typeFrom,类型typeTo,字符串名称,LifetimeManager lifetimeManager,InjectionMember [] injectionMembers)    在Unity.UnityContainerExtensions.RegisterType [TFrom,TTo](IUnityContainer容器,InjectionMember [] injectionMembers)    在D:\ Programs \ 2018 \ OxfordLibrary \ OxfordLibrary \ App_Start \ UnityConfig.cs:第35行中的OxfordLibrary.App_Start.UnityConfig.RegisterComponents()中    在D:\ Programs \ 2018 \ OxfordLibrary \ OxfordLibrary \ Global.asax.cs:第20行的OxfordLibrary.MvcApplication.Application_Start()中

0 个答案:

没有答案