Merge MyDbContext with IdentityDbContext

前端 未结 8 1859
天命终不由人
天命终不由人 2020-11-28 22:22

I have a MyDbContext in a separated Data Accass Layer class library project. And I have an ASP.NET MVC 5 project with a default IdentityDbContext. The two context use the sa

8条回答
  •  日久生厌
    2020-11-28 23:09

    It's worth noting that if you merge the DBContexts you are tying an authentication approach (ASP's Identity in this case) to the data access implementation (EF). From a code design point of view that could be seen as mixing your concerns and a violation of Single Responsibility Principle.

    That's probably fine in the majority of cases, but if you want to reuse your data layer in other non-web applications (e.g. for a desktop or server app) this will present an issue because IdentityDbContext lives in the Microsoft.AspNet.Identity.EntityFramework namespace and your desktop or server apps are unlikely to be using AspNet Identity as their authentication mechanism.

    We were in that situation and ended up keeping ASP's second DB Context, which stayed in the web project. We then cross-loaded some of the data about the user (first name, last name, etc.) into the Identity's claims object when the user signed in.

提交回复
热议问题