简体   繁体   中英

EntityFrameworkCore Identity

I have created a brand new ASP.Net Core web application, and enabled Identity services. The framework helpfully creates me a number of view and view models to handle the task to creating, validating and removing users; however, I'm a little confused about the EF component of this (I'm quite a newcomer to EF, so I'm possibly missing something).

The AccountController has UserManager<ApplicationUser> userManager injected into it and, for example, for account creation, calls something like:

var result = await _userManager.CreateAsync(user, model.Password);

As I understand what this is doing, it is calling functionality within Microsoft.AspNetCore.Identity that maps (directly) to a table in the DB (by default dbo.ASPNetUsers - or similar). Typically, I would expect such functionality to sit in a service which communicates with the DB; this provides a layer of abstraction and a gateway to the database.

My question is, is the above functionality giving the same thing in some sense, or are we, effectively, communicating directly with the DB from the web site?

UserManager depends on IUserStore interface of which there is an implementation that uses EFCore that gets injected into UserManager. It is also possible to make other implementations of the various interfaces. So there is layering, UserManager is not talking directly to the db but to service interfaces.

The great thing is it is all open source so if you want to see how things work you can easily https://github.com/aspnet/Identity/tree/dev/src

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM