小编Vla*_*hub的帖子

带有数据库上下文工厂的身份存储

在我的 ASP.NET Core 5.0 项目中,我改变了

services.AddDbContext<SelfProgressDbContext>(...);
Run Code Online (Sandbox Code Playgroud)

services.AddPooledDbContextFactory<SelfProgressDbContext>(...);
Run Code Online (Sandbox Code Playgroud)

现在应用程序没有启动。我得到的错误的子集:

验证服务描述符“ServiceType:Microsoft.AspNetCore.Identity.UserManager 1[SelfProgress.Domain.User] Lifetime: Scoped ImplementationType: Microsoft.AspNetCore.Identity.UserManager1[SelfProgress.Domain.User]”时出错:尝试激活>“Microsoft.AspNetCore.Identity”时无法解析类型“SelfProgress.Orm.SelfProgressDbContext”的服务.EntityFrameworkCore.UserStore 9[SelfProgress.Domain.User,Microsoft.AspNetCore.Identity.IdentityRole1[System.Guid]、SelfProgress.Orm.SelfProgressDbContext、System.Guid、Microsoft.AspNetCore.Identity.IdentityUserClaim 1[System.Guid],Microsoft.AspNetCore.Identity.IdentityUserRole1[System.Guid]、Microsoft.AspNetCore.Identity.IdentityUserLogin 1[System.Guid],Microsoft.AspNetCore.Identity.IdentityUserToken1[System.Guid]、Microsoft .AspNetCore.Identity.IdentityRoleClaim`1[System.Guid]]'。

验证服务描述符'ServiceType:Microsoft.AspNetCore.Identity.ISecurityStampValidator Lifetime:Scoped ImplementType:Microsoft.AspNetCore.Identity.SecurityStampValidator 1[SelfProgress.Domain.User]': Unable to resolve service for type 'SelfProgress.Orm.SelfProgressDbContext' while attempting to activate 'Microsoft.AspNetCore.Identity.EntityFrameworkCore.UserStore9[SelfProgress.Domain.User,Microsoft.AspNetCore.Identity.IdentityRole 1[System.Guid],SelfProgress.Orm.SelfProgressDbContext,System.Guid,Microsoft.AspNetCore.Identity.IdentityUserClaim1[System.Guid]时出错, Microsoft.AspNetCore.Identity.IdentityUserRole 1[System.Guid],Microsoft.AspNetCore.Identity.IdentityUserLogin1[System.Guid],Microsoft.AspNetCore.Identity.IdentityUserToken 1[System.Guid],Microsoft.AspNetCore.Identity.IdentityRoleClaim1[System.Guid]]'。

验证服务描述符“ServiceType:Microsoft.AspNetCore.Identity.RoleManager 1[Microsoft.AspNetCore.Identity.IdentityRole1 [System.Guid]]生命周期时出错:作用域实现类型:Microsoft.AspNetCore.Identity.RoleManager 1[Microsoft.AspNetCore.Identity.IdentityRole1 [System.Guid]]”:无法解析类型的服务尝试激活“Microsoft.AspNetCore.Identity.EntityFrameworkCore.RoleStore 5[Microsoft.AspNetCore.Identity.IdentityRole1[System.Guid]、SelfProgress.Orm.SelfProgressDbContext、System.Guid、Microsoft.AspNetCore.Identity.IdentityUserRole 1[System.Guid],Microsoft.AspNetCore.Identity.IdentityRoleClaim1[System.Guid”时出现“SelfProgress.Orm.SelfProgressDbContext” ]]'。

由于新的池数据库上下文工厂注册,Identity EF 存储类似乎无法再解析数据库上下文。使用AddPooledDbContextFactory似乎您无法再直接解析数据库上下文。相反,您应该解析工厂,然后手动创建数据库上下文。

我的身份注册:

services
    .AddIdentity<User, IdentityRole<Guid>>(...)
    .AddEntityFrameworkStores<SelfProgressDbContext>()
    .AddDefaultTokenProviders()
Run Code Online (Sandbox Code Playgroud)

有没有办法让默认身份存储通过其新工厂解析数据库上下文?

entity-framework-core asp.net5 asp.net-core-identity .net-5 asp.net-core-5.0

7
推荐指数
1
解决办法
1471
查看次数