Because it always feels like the asp.net identity is not comfortable to use, such as the extensibility of the Code, and the maintenance of later versions, so analyze it
Enter the following text:
In the default program of VS2015, App_start/identityconfig.cs, through the Applicationusermanager create function, the main content of the function is as follows
public static Applicationusermanager Create (identityfactoryoptions<applicationusermanager> options, Iowincontext context)
{
var manager = new Applicationusermanager (New userstore<applicationuser> ( Context. Get<applicationdbcontext> ()));
..........
It can be concluded that the function initializes, creates a new Applicationusermanager class (the class itself), passes in a new Userstore generic class, and gives the Userstore generic class A view of the class definition, passed in DbContext Context Parameters
In the Microsoft.AspNet.Identity.EntityFramework binary DLL, the userstore new user's function is
Public async Virtual Task createasync (TUser user)
{(
userstore<tuser, Trole, TKey, Tuserlogin, Tuserrole, tuserclaim>) this). Throwifdisposed ();
if (user = = null)
{
throw new ArgumentNullException ("user");
}
((Userstore<tuser, Trole, TKey, Tuserlogin, Tuserrole, tuserclaim>) this). _userstore.create (user);
Await (Userstore<tuser, Trole, TKey, Tuserlogin, Tuserrole, tuserclaim>) this). SaveChanges (). Withcurrentculture ();
}
You can see that the key to the operation of the database is _userstore.create, while the _userstore field is initialized to
This._userstore = new entitystore<tuser> (context);
In addition to the management of roles, the _rolestore field
This._rolestore = new entitystore<trole> (context);
Entitystore generics, manipulating the database through an internal call to EntityFramework
public void Create (tentity entity)
{this
. Dbentityset.add (entity);
}
It's a way to know that you're building your own operations on the database and integrating with ASP.net identity
Attach the Entitystore code
Namespace Microsoft.AspNet.Identity.EntityFramework {using System;
Using System.Data.Entity;
Using System.Linq;
Using System.Runtime.CompilerServices;
Using System.Threading.Tasks;
Internal class entitystore<tentity> where Tentity:class {public entitystore (DbContext context) {this.
context = context; This. Dbentityset = context.
Set<tentity> (); } public void Create (tentity entity) {this.
Dbentityset.add (entity); } public void Delete (tentity entity) {this.
Dbentityset.remove (entity); Public virtual task<tentity> Getbyidasync (object ID) {return this.
Dbentityset.findasync (new object[] {ID});
public virtual void Update (tentity entity) {if (entity!= null) { This. context.entry<tentity> (entity).
state = entitystate.modified;
} public DbContext context {get; private set;}
Public dbset<tentity> Dbentityset {get; private set;} Public iqueryable<tentity> EntitySet {get {return this.
Dbentityset; }
}
}