Accessing by DbContext vs UserManager

asp.net-core asp.net-core-identity c# entity-framework-core

Question

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(..)
1
3
4/20/2018 11:25:54 AM

Popular Answer

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.

By using 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.

The 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.

4
4/20/2018 11:31:12 AM


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow