ASP.NET Core 2.1 Role Manager Register

后端 未结 1 1951
庸人自扰
庸人自扰 2021-01-22 12:16

In my seeding code I create Users and Roles, and the error seems to be whenever I run it through startup I seem to be getting

\"No service for type

相关标签:
1条回答
  • 2021-01-22 12:25

    You haven't registered the role services in the DI container. This line:

    services.AddDefaultIdentity<AppUser>()
        .AddEntityFrameworkStores<ApplicationDbContext>();
    

    Needs to change to include them by using the AddRoles method. Assuming you are using the default IdentityRole class:

    services.AddDefaultIdentity<AppUser>()
        .AddRoles<IdentityRole>()
        .AddEntityFrameworkStores<ApplicationDbContext>();
    
    0 讨论(0)
提交回复
热议问题