Custom ASP.NET Identity 2.0 UserStore - Is implementing all interfaces required?

前端 未结 3 980
醉酒成梦
醉酒成梦 2021-02-07 04:18

I\'ve created a custom IUserStore for my application. I\'ve implemented the interfaces I need,

   IUserStore,
           


        
3条回答
  •  隐瞒了意图╮
    2021-02-07 04:37

    I had the same problem and I don't want to implement the IUserTwoFactorStore just to say that I don't implement it. But I also don't want to go back and muck around if I end up wanting to implement it (which I anticipate I will). So what I consider a future proof (and reusable) solution would be: (inspired by @gjsduarte's answer)

    public class SafeUserManager : UserManager
    {
        public override Task GetTwoFactorEnabledAsync(TKey userId)
        {
            return Store is IUserTwoFactorStore
                ? base.GetTwoFactorEnabledAsync(userId)
                : Task.FromResult(false);
        }
    }
    

    It would probably be a good idea to do the same for the other Get[feature]EnabledAsync(TKey userId) methods.

提交回复
热议问题