为什么我在设置 Unity 依赖注入后登录时出现错误?
Why am I getting an error logging in after setting up Unity Dependency Injection?
我正在使用 C# ASP.NET 使用 MVC5 和 EF6 构建一个站点。我刚刚为数据库模型设置了一个单独的项目,并为存储库设置了一个单独的项目作为数据访问层。
我现在尝试登录该站点时遇到以下错误:
The entity type ApplicationUser is not part of the model for the current context.
引发错误的行是:
var result = await UserManager.CreateAsync(user, model.Password);
我的 UnityConfig 文件注册了以下类型:
container.RegisterType<IUnitOfWork, UnitOfWork>();
container.RegisterType(typeof(IUserStore<ApplicationUser>), typeof(UserStore<ApplicationUser>));
container.RegisterType<UserManager<ApplicationUser>, ApplicationUserManager>();
container.RegisterType<SignInManager<ApplicationUser, string>, ApplicationSignInManager>();
container.RegisterType<DbContext, BlogModelContainer>();
container.RegisterType<ApplicationDbContext>(new InjectionFactory(c => HttpContext.Current.GetOwinContext().Authentication));
container.RegisterType<IAuthenticationManager>(new InjectionFactory(c => HttpContext.Current.GetOwinContext().Authentication));
我想我在这里漏掉了另一行,但还没有设法解决。这可能与我需要包含的 DefaultConnection
有关吗?
这在我开始将 Unity 放入项目之前就奏效了。任何帮助表示赞赏。让我知道是否需要包含任何其他详细信息。
找到解决方案。
基本上,如果您要将 Unity 与 MVC5 一起使用,则需要使用正确的 Nuget 包。
我不小心使用了 Unity.Mvc 包,而我本应该使用 Unity.Mvc5。更正此问题后,一切如我所料(本教程对我正在做的事情也很有用,但不是必需的http://tech.trailmax.info/2014/09/aspnet-identity-and-ioc-container-registration/)。
我正在使用 C# ASP.NET 使用 MVC5 和 EF6 构建一个站点。我刚刚为数据库模型设置了一个单独的项目,并为存储库设置了一个单独的项目作为数据访问层。
我现在尝试登录该站点时遇到以下错误:
The entity type ApplicationUser is not part of the model for the current context.
引发错误的行是:
var result = await UserManager.CreateAsync(user, model.Password);
我的 UnityConfig 文件注册了以下类型:
container.RegisterType<IUnitOfWork, UnitOfWork>();
container.RegisterType(typeof(IUserStore<ApplicationUser>), typeof(UserStore<ApplicationUser>));
container.RegisterType<UserManager<ApplicationUser>, ApplicationUserManager>();
container.RegisterType<SignInManager<ApplicationUser, string>, ApplicationSignInManager>();
container.RegisterType<DbContext, BlogModelContainer>();
container.RegisterType<ApplicationDbContext>(new InjectionFactory(c => HttpContext.Current.GetOwinContext().Authentication));
container.RegisterType<IAuthenticationManager>(new InjectionFactory(c => HttpContext.Current.GetOwinContext().Authentication));
我想我在这里漏掉了另一行,但还没有设法解决。这可能与我需要包含的 DefaultConnection
有关吗?
这在我开始将 Unity 放入项目之前就奏效了。任何帮助表示赞赏。让我知道是否需要包含任何其他详细信息。
找到解决方案。
基本上,如果您要将 Unity 与 MVC5 一起使用,则需要使用正确的 Nuget 包。
我不小心使用了 Unity.Mvc 包,而我本应该使用 Unity.Mvc5。更正此问题后,一切如我所料(本教程对我正在做的事情也很有用,但不是必需的http://tech.trailmax.info/2014/09/aspnet-identity-and-ioc-container-registration/)。