Is there drawbacks or advantages in using either UserManager or DbContext?
If I use this:
public class UserManager<TUser> : IDisposable where TUser : class public virtual Task<TUser> FindByIdAsync(string userId);
Or if I use direct dbcontext like:
var user = dbContext.Users.Where(x => x.Id == model.Id).FirstOrDefault(); // Login like this await HttpContext.SignInAsync(..)
Today, you query your users from your database. What if you decided to delegate the authentication to an authorization server? I've seen this happen before: people decide to create a Web API to deal with authentication/authorization details. If you were using the
DbContext directly, you would have to change everywhere you would be using it.
UserManager on the other hand, you would just have to change the implementation of your
UserManager to use an
HttpClient, to consume a Web API in order to query users, roles and other stuff needed to create your user Identity.
UserManager encapsulates the implementation details through the
IUserStore and some other interfaces. I'd avoid querying any of the Identity tables directly, even though it's very tentative.