2017-10-27 20 views
3

ROLES에 CRUD 작업을 만들어야합니다.AspNetCore 2.0 ID - RoleManager 삽입 문제

그래서, 내가 어떻게으로 roleManager를 주입 할 수 있습니다 " 'Microsoft.AspNetCore.Identity.RoleManager` 유형의 서비스를 확인할 수 없습니다"

나는 다음과 같은 오류를 받고 있어요?

내가 사용 ASP를 그물 코어 2.0 + 정체성 2.2.1

클래스 ApplicationUser

Startup.cs

에서 지금
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` 유형의 서비스를 확인할 수 없습니다.

답변

0

AddRoleStore <> 대신 .AddRoleManager <>을 사용해야합니다. 또는 둘 모두 새 역할을 작성하려는 경우에 사용하십시오. 맞춤 상점을 사용하지 않으시는 분 : AddEntityFrameworkStores

services.AddIdentity<ApplicationUser, IdentityRole>() 
       .AddEntityFrameworkStores<YourContext>()