首页 > 解决方案 > 如何在跨解决方案共享的数据库项目中引用 IdentityDbContext

问题描述

我想利用 ASP.NET Core 项目的 Visual Studio 模板中现成的 IdentityDbContext。但是,我希望我的实体和迁移存在于共享项目中,以供解决方案的不同组件(Web、API、后台服务等)引用。

我的共享数据库项目将是一个 .NET Standard 项目,但看起来我必须添加对Microsoft.AspNetCore.Identity.EntityFrameworkCore. 向标准项目引入对专门用于 ASP.NET 的核心程序集的依赖项感觉很奇怪。这会带来什么问题吗?

标签: c#asp.net-core.net-coreentity-framework-core.net-standard

解决方案


You must inherit some of Identity classes(IdentityUser) for your Entity objects so you must reference the Microsoft.AspNetCore.Identity.EntityFrameworkCore but I do not recommend to store Identity classes with other Entity classes related to your business layer.

Identity is about infrastructure of your project. Just store Identity related classes Dbbontext, entity classes and services on the same project that you already store Db access codes thats reference EntityFrameworkCore.

Holding two different projects on solution that reference EntityFrameworkCore just a violation of seperation of concerns not more. If you want to hold 2 different projects just use same versions of EfCore.


推荐阅读