无法为ASP.Net Core 2.0解析Microsoft.AspNetCore.Identity.RoleManager类型的服务

时间:2018-06-02 02:18:10

标签: asp.net-core asp.net-core-identity

如何在ASP.Net Core 2.0中注入RoleManager?

我收到以下错误:

  

无法解析类型的服务   用于ASP.Net Core 2.0的Microsoft.AspNetCore.Identity.RoleManager

我有以下代码:

  // add identity
  var builder = services.AddIdentityCore<AppUser>(o =>
  {
    // configure identity options
    o.Password.RequireDigit = false;
    o.Password.RequireLowercase = false;
    o.Password.RequireUppercase = false;
    o.Password.RequireNonAlphanumeric = false;
    o.Password.RequiredLength = 6;
  });
  builder = new IdentityBuilder(builder.UserType, typeof(AppRole), builder.Services);
  builder.AddSignInManager<SignInManager<AppUser>>();

AppUser和AppRole分别来自IdentityUser和IdentityRole。

1 个答案:

答案 0 :(得分:2)

我不确定您使用AddIdentity()的原因。您是否尝试过传统的services.AddIdentity<AppUser, AppRole>(options => { ... });

bootstrap.scss