访问 Microsoft.Extensions.Hosting 服务时出现问题。使用 AddPooledDbContextFactory
Posted
技术标签:
【中文标题】访问 Microsoft.Extensions.Hosting 服务时出现问题。使用 AddPooledDbContextFactory【英文标题】:A issue occurred while accessing the Microsoft.Extensions.Hosting services. Using AddPooledDbContextFactory 【发布时间】:2021-07-02 14:47:04 【问题描述】:您好,我在迁移时遇到问题,并且显示访问 Microsoft.Extensions.Hosting 服务时出现错误。在没有应用程序服务提供商的情况下继续。错误:某些服务无法构建(E
验证服务描述符“ServiceType:Microsoft.AspNetCore.Identity.IUserClaimsPrincipalFactory1[GraphQlApiFullStack.Models.AppUser] Lifetime: Scoped Implementati onType: Microsoft.AspNetCore.Identity.UserClaimsPrincipalFactory
1[GraphQlApiFullStack.Models.AppUser]”时出错:无法解析类型“GraphQlApiFullStack.Data.ApplicationDbConte”的服务
xt 尝试激活 'Microsoft.AspNetCore.Identity.EntityFrameworkCore.UserOnlyStore
谁能帮帮我,谢谢。
ApplicationDbContext.cs
using GraphQlApiFullStack.Models;
using Microsoft.AspNetCore.Identity.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore;
namespace GraphQlApiFullStack.Data
public class ApplicationDbContext : IdentityDbContext<AppUser>
public ApplicationDbContext(DbContextOptions<ApplicationDbContext> options) : base(options)
public DbSet<AppUser> AppUsers get; set;
public DbSet<Employee> Employees get; set;
public DbSet<Department> Departments get; set;
Startup.cs 服务
public void ConfigureServices(IServiceCollection services)
services.AddControllers();
services.AddSwaggerGen(c =>
c.SwaggerDoc("v1", new OpenApiInfo Title = "GraphQlApiFullStack", Version = "v1" );
);
// We use a pooled Db Context Factory here to avoid issues with graphql concurrency
services.AddPooledDbContextFactory<ApplicationDbContext>(builder =>
builder.UseSqlServer(_configuration.GetConnectionString("defaultConnection"));
);
services.AddIdentityServices(_configuration);
```
【问题讨论】:
【参考方案1】:好的,我发现问题出在我的身份服务扩展方法上。
【讨论】:
以上是关于访问 Microsoft.Extensions.Hosting 服务时出现问题。使用 AddPooledDbContextFactory的主要内容,如果未能解决你的问题,请参考以下文章