【问题标题】:.net core 2.0 Resolver issue with identityrole.net core 2.0 解析器问题与身份角色
【发布时间】:2018-11-30 07:51:54
【问题描述】:

我将 IdentityRole 用户键自定义为 int 而不是 string。这就是我尝试将其添加到服务集合的方式。

首先我的应用程序用户继承自 identityUser

public class ApplicationUser : IdentityUser<int>......

然后在我的服务集合中:

services.AddIdentity<ApplicationUser, IdentityRole<int>>(options => {
            // Password settings
            options.Password.RequireDigit = true;
            options.Password.RequiredLength = 8;.......`

在基本控制器中,我有以下构造函数:

public BaseApiController(RoleManager<IdentityRole> roleManager, UserManager<ApplicationUser> userManager, IConfiguration configuration, ILogger<BaseApiController> logger) : base(logger)
        {
            _roleManager = roleManager;
            _userManager = userManager;
            _configuration = configuration;

            _jsonSettings = new JsonSerializerSettings() { Formatting = Formatting.Indented };
        }

然后我在我的一个 mvc 控制器上使用基本控制器,格式如下:

 public class RegisterController : BaseApiController
    {
        private readonly IAccountService _accountService;

        public RegisterController(RoleManager<IdentityRole> roleManager, UserManager<ApplicationUser> userManager, IConfiguration configuration, ILogger<RegisterController> logger, IAccountService accountService) : base(roleManager, userManager, configuration, logger)
        {
            _accountService =  accountService;

        }

现在当我使用 swagger 运行时,我收到以下错误:

处理请求时发生未处理的异常 Microsoft.AspNetCore.Identnty.RoleManager 类型的解析服务 尝试激活时 Myprog.Areas.Account.Controllers.RegisterController

【问题讨论】:

    标签: c# asp.net-mvc asp.net-identity asp.net-core-2.0


    【解决方案1】:

    基本控制器需要在调用中分配,然后在所有实现中执行:

    public BaseApiController(RoleManager<IdentityRole<int>> roleManager, UserManager<ApplicationUser> userManager, IConfiguration configuration, ILogger<BaseApiController> logger) : base(logger)
    

    【讨论】:

      猜你喜欢
      • 2018-07-03
      • 2018-04-01
      • 2020-01-24
      • 2018-12-21
      • 2020-02-24
      • 2021-04-16
      • 2018-04-03
      • 1970-01-01
      • 2021-04-15
      相关资源
      最近更新 更多