If you are not satisfied with the standard methods that Identity 2.0 works with the base, you can completely replace it with your own:
Announce your type to the user:
public class ApplicationUser : IUser { ... }
Declare your own user repository type and implement it using an existing BLL / DAL:
public class CustomUserStore : IUserStore<ApplicationUser> { ... }
Declare a heir from UserManager:
public class CustomUserManager : UserManager<ApplicationUser> { public CustomUserManager(CustomUserStore store) : base(store) { this.PasswordHasher = new CustomPasswordHasher(); } public static CustomUserManager Create(IdentityFactoryOptions<CustomUserManager> options, IOwinContext context) { var manager = new CustomUserManager(new CustomUserStore<ApplicationUser>()); return manager; } }
and register the CustomUserManager
in App_Start:
app.CreatePerOwinContext<CustomUserManager>(CustomUserManager.Create);
CustomUserStore
and CustomUserManager
relocate or in BLL, or partially leave in the PLL (depending on how you implement them). I would leave them in the PLL by writing BLL calls in their methods.
Or, perhaps, the standard implementation of UserStore
will be enough for UserStore
, then it will be enough to create an empty class that CustomUserManager
and register both it and the factory for the shortcut:
public static ApplicationDbContext Create() { return new ApplicationDbContext(); } public static CustomUserManager Create(IdentityFactoryOptions<CustomUserManager> options, IOwinContext context) { var manager = new CustomUserManager((new UserStore<ApplicationUser>(context.Get<ApplicationDbContext>()));); return manager; } public void ConfigureAuth(IAppBuilder app) { app.CreatePerOwinContext<ApplicationDbContext>(ApplicationDbContext.Create); app.CreatePerOwinContext<CustomUserManager>(CustomUserManager.Create); }
I did not check the code live, but it should work