【问题标题】:A issue occurred while accessing the Microsoft.Extensions.Hosting services. Using AddPooledDbContextFactory访问 Microsoft.Extensions.Hosting 服务时出现问题。使用 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.UserClaimsPrincipalFactory1[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);

        }
    ```

【问题讨论】:

    标签: c# entity-framework asp.net-core entity-framework-migrations


    【解决方案1】:

    好的,我发现问题出在我的身份服务扩展方法上。

    【讨论】:

      猜你喜欢
      • 2020-06-19
      • 2021-03-24
      • 1970-01-01
      • 2021-03-18
      • 1970-01-01
      • 2011-08-31
      • 1970-01-01
      • 2016-06-25
      • 1970-01-01
      相关资源
      最近更新 更多