MVC 5 IoC and Authentication

前端 未结 4 1042
借酒劲吻你
借酒劲吻你 2020-12-24 09:46

I am just about to start on a project, where I will be using MVC5. But as I want to use IoC and later reuse my user tables, and add custom stuff to it, I am finding it very

4条回答
  •  野趣味
    野趣味 (楼主)
    2020-12-24 10:09

    If all you need is to inject custom UserStore implementation this article may help you

    Basically you need to inject this (depends if you want to use roles, claims etc..):

    1. Write a User class that implements the IUser interface

      public class IdentityUser : IUser {
          public IdentityUser(){...}
          public IdentityUser(string userName) (){...}
          public string Id { get; set; }
          public string UserName { get; set; }
          public string PasswordHash { get; set; }
          public string SecurityStamp { get; set; }  
      }
      
    2. Write a User store class that implements the IUserStore, IUserClaimStore, IUserLoginStore, IUserRoleStore and IUserPasswordStore

      public class UserStore : IUserStore,
          IUserClaimStore,
          IUserLoginStore,
          IUserRoleStore,
          IUserPasswordStore {
      
          public UserStore(){...}
          public Task CreateAsync(IdentityUser user){...}
          public Task FindByIdAsync(string userId){...}   
          .. .
      }
      

提交回复
热议问题