Creating a UserManager outside of built in dependency injection system

后端 未结 3 1224
太阳男子
太阳男子 2021-01-04 11:24

This is using asp.net core with identity and entity framework core. I working on a saas application where I have a separate admin web app where you can add new tenants to t

相关标签:
3条回答
  • 2021-01-04 11:37

    The solution of the problem in this way

    static IUserStore<ApplicationUser> _store = new UserStore<ApplicationUser>(new context()); 
    static UserManager<ApplicationUser> _userManager = new UserManager<ApplicationUser>(_store, null, new PasswordHasher<ApplicationUser>(), null, null, null, null, null, null);
    
    0 讨论(0)
  • 2021-01-04 11:54

    After looking through the identity source you can pass nulls in to get the correct results. Should have just tried this first.

    0 讨论(0)
  • 2021-01-04 12:00

    I would think you should have at least the UserStore:

     UserStore<ApplicationUser> _userStore = new UserStore<ApplicationUser>(context, null);
     Mock<ILogger<UserManager<ApplicationUser>>> mockLogger = null;
     mockLogger = new Mock<ILogger<UserManager<ApplicationUser>>>();
    

    I mocked the logger.

    0 讨论(0)
提交回复
热议问题