ASP.NET Core 2 - Identity - DI errors with custom Roles

前端 未结 1 459
花落未央
花落未央 2021-01-07 21:39

I got this code in my Startup.cs:

 services.AddDbContext(options =>
            options.UseSqlServer(Configuration.GetConnecti         


        
1条回答
  •  星月不相逢
    2021-01-07 22:10

    You have to create the IServiceScope on your own.

    To do this you have to replace

    var roleManager = serviceProvider.GetService>();
    

    with

    using (IServiceScope scope = app.ApplicationServices.CreateScope()) {
        RoleManager roleManager = scope.ServiceProvider.GetRequiredService>();
    
        // Seed database code goes here
    }
    

    0 讨论(0)
提交回复
热议问题