asp.net 2.0标识不统一解决默认的用户存储 [英] asp.net identity 2.0 unity not resolving default user store

本文介绍了asp.net 2.0标识不统一解决默认的用户存储的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

尝试配置使用Unity.Mvc5与使用Identity 2.0和样板标识2.0样品的MVC 5应用程序统一时,我得到下面的异常。我已阅读本SO 配置统一DI为ASP.NET身份并我还没有对我缺少什么,我不清楚。我究竟做错了什么?

当前类型,System.Data.Common.DbConnection,是一个抽象类,不能构成。是否缺少类型映射?

[ResolutionFailedException:依赖关系解析失败,TYPE =myApp.Web.Controllers.AccountControllerNAME =(无)。
在解析

:当发生异常。

异常是:出现InvalidOperationException - 当前类型,System.Data.Common.DbConnection,是一个抽象类,不能构成。是否缺少类型映射?

目前的异常时,该容器是:

解决myApp.Web.Controllers.AccountController,(无)
解决构造myApp.Web.Controllers.AccountController的参数的UserManager(myApp.Web.Models.ApplicationUserManager的UserManager)
解决myApp.Web.Models.ApplicationUserManager,(无)
解决构造函数参数专卖店 myApp.Web.Models.ApplicationUserManager(Microsoft.AspNet.Identity.IUserStore<$c$c>1[[myApp.Web.DAL.Profiles.ApplicationUser, myApp.Web,版本= 1.0.0.0,文化=中立,公钥=空]店)
解决Microsoft.AspNet.Identity.EntityFramework.UserStore1[myApp.Web.DAL.Profiles.ApplicationUser],(none) (从Microsoft.AspNet.Identity.IUserStore映射 1 [myApp.Web.DAL.Profiles.ApplicationUser],(无))
解决构造Microsoft.AspNet.Identity.EntityFramework.UserStore
参数背景1 [myApp.Web.DAL.Profiles.ApplicationUser,myApp.Web,版本= 1.0.0.0,文化=中立,公钥=空](System.Data.Entity.DbContext上下文)
解决System.Data.Entity.DbContext,(无)
解决参数existingConnection构造System.Data.Entity.DbContext的(System.Data.Common.DbConnection existingConnection,System.Data.Entity.Infrastructure.DbCompiledModel模型,System.Boolean contextOwnsConnection)
解决System.Data.Common.DbConnection,(无)

帐户控制器我已经修改了它

 公开的AccountController(ApplicationUserManager的UserManager)
 {
      _userManager =的UserManager;
 } 私人ApplicationUserManager _userManager;

容器我已经注册

  container.RegisterType&LT; ApplicationUserManager&GT;(新HierarchicalLifetimeManager());
container.RegisterType&所述; IUserStore&下; ApplicationUser&gt;中UserStore&所述; ApplicationUser&GT;&GT;(新HierarchicalLifetimeManager());


解决方案

我看到你找到了解决办法,但我想我有一个简单的办法。

您正在使用实体框架,对不对?所以,你的应用程序几乎可以肯定有东西从的DbContext 继承(大概是从 IdentityContext&LT继承; TUSER&GT; ,这反过来从继承在这种情况下,的DbContext )。在默认的模板是ApplicationDbContext。

在你的作文根,你可以再补充 container.RegisterType&LT;的DbContext,ApplicationDbContext&GT;(新HierarchicalLifetimeManager()); (显然编辑这个,如果你不叫ApplicationDbContext )。

i get the following exception when trying to configure Unity using Unity.Mvc5 with an MVC 5 application using Identity 2.0 and the Identity 2.0 Samples boilerplate. i have read this SO Configure Unity DI for ASP.NET Identity and i'm still not clear on what i'm missing. What am i doing wrong here?

The current type, System.Data.Common.DbConnection, is an abstract class and cannot be constructed. Are you missing a type mapping?

[ResolutionFailedException: Resolution of the dependency failed, type = "myApp.Web.Controllers.AccountController", name = "(none)". Exception occurred while: while resolving.

Exception is: InvalidOperationException - The current type, System.Data.Common.DbConnection, is an abstract class and cannot be constructed. Are you missing a type mapping?

At the time of the exception, the container was:

Resolving myApp.Web.Controllers.AccountController,(none) Resolving parameter "userManager" of constructor myApp.Web.Controllers.AccountController(myApp.Web.Models.ApplicationUserManager userManager) Resolving myApp.Web.Models.ApplicationUserManager,(none) Resolving parameter "store" of constructor myApp.Web.Models.ApplicationUserManager(Microsoft.AspNet.Identity.IUserStore1[[myApp.Web.DAL.Profiles.ApplicationUser, myApp.Web, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]] store) Resolving Microsoft.AspNet.Identity.EntityFramework.UserStore1[myApp.Web.DAL.Profiles.ApplicationUser],(none) (mapped from Microsoft.AspNet.Identity.IUserStore1[myApp.Web.DAL.Profiles.ApplicationUser], (none)) Resolving parameter "context" of constructor Microsoft.AspNet.Identity.EntityFramework.UserStore1[[myApp.Web.DAL.Profiles.ApplicationUser, myApp.Web, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]](System.Data.Entity.DbContext context) Resolving System.Data.Entity.DbContext,(none) Resolving parameter "existingConnection" of constructor System.Data.Entity.DbContext(System.Data.Common.DbConnection existingConnection, System.Data.Entity.Infrastructure.DbCompiledModel model, System.Boolean contextOwnsConnection) Resolving System.Data.Common.DbConnection,(none)

account controller as i have modified it

 public AccountController(ApplicationUserManager userManager)
 {
      _userManager = userManager;
 }

 private ApplicationUserManager _userManager;

containers i have registered

container.RegisterType<ApplicationUserManager>(new HierarchicalLifetimeManager());
container.RegisterType<IUserStore<ApplicationUser>, UserStore<ApplicationUser>>(new HierarchicalLifetimeManager());

解决方案

I see you found a solution, but I think I have a simpler one.

You're using Entity Framework, right? So your application almost certainly has something inheriting from DbContext (probably inheriting from IdentityContext<TUser>, which in turn inherits from DbContext in this case). In the default template it's ApplicationDbContext.

In your composition root you can just add container.RegisterType<DbContext, ApplicationDbContext>(new HierarchicalLifetimeManager()); (obviously edit this if yours isn't called ApplicationDbContext).

这篇关于asp.net 2.0标识不统一解决默认的用户存储的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆