3
私はROLESのCRUD操作を作成する必要があります。私は次のエラーを取得していますAspNetCore 2.0 ID - RoleManagerの注入に関する問題
:
「タイプのサービスを解決できません「Microsoft.AspNetCore.Identity.RoleManager`」
をので、どのように私はroleManagerを注入することができますか? Startup.cs
で今私は、ASPネットコア2.0 + IDを使用しています2.2.1
クラスApplicationUser
public class ApplicationUser : IdentityUser
{
[Key]
public override string Id { get; set; }
public bool Type { get; set; }
}
services.AddIdentity<ApplicationUser, IdentityRole<int>>()
.AddUserStore<UserStore<ApplicationUser, IdentityRole<int>, ApplicationDbContext, int>>()
.AddRoleStore<RoleStore<IdentityRole<int>, ApplicationDbContext, int>>()
.AddDefaultTokenProviders();
コントローラ
private readonly UserManager<ApplicationUser> _userManager;
private readonly RoleManager<IdentityUser> _roleManager;
public RolesController(UserManager<ApplicationUser> userManager, RoleManager<IdentityUser> roleManager)
{
_userManager = userManager;
_roleManager = roleManager;
}
public IActionResult Index()
{
return View(_roleManager.Roles);
}
など、 私はエラーが発生します: "タイプ 'Microsoft.AspNetCore.Identity.RoleManager`のサービスを解決することができません。