How to register custom UserStore & UserManager in DI

后端 未结 3 1499
-上瘾入骨i
-上瘾入骨i 2020-12-28 19:01

Here is my setup:

public class ApplicationUser : IdentityUser
{
}
public class ApplicationRole : IdentityRole
{
}
public class Applic         


        
3条回答
  •  时光说笑
    2020-12-28 19:28

    I am now on ASP.NET Core 1.1 and this behavior has been fixed.

    I can easily implement my own UserManager and UserStore, then bootstrap the app as following:

    // identity models
    services
        .AddIdentity()
        .AddEntityFrameworkStores()
        .AddUserManager()
        .AddUserStore()
        .AddDefaultTokenProviders();
    

    and inject both UserManager and UserStore into my Controller, without any problem:

    public AccountController(
        IIdentityServerInteractionService interaction,
        IClientStore clientStore,
        IHttpContextAccessor httpContextAccessor,
        ApplicationUserManager userManager,
        SignInManager signInManager,
        IEmailSender emailSender,
        ISmsSender smsSender,
        ILoggerFactory loggerFactory)
    {
        _interaction = interaction;
        _userManager = userManager;
        _signInManager = signInManager;
        _emailSender = emailSender;
        _smsSender = smsSender;
        _logger = loggerFactory.CreateLogger();
        _account = new AccountService(_interaction, httpContextAccessor, clientStore);
    }
    

提交回复
热议问题