将 EF6 添加到 razor class 库项目以供多个 BLAZOR 项目共享?

Add EF6 to a razor class library project to be shared by many BLAZOR projects?

是否可以将 EF6 添加到剃须刀 class 库中?目标是让其他 BLAZOR 项目共享许多组件,但其中许多控件需要访问数据库,这对于此解决方案中的所有项目都是相同的。另外,我假设数据库访问将通过控制器进行,因为不可能作为服务注入。这是正确的吗?

Is it possible to add EF6 to a razor class library ?

是的,但您会立即限制 Blazor 服务器端的库。

a lot of these controls require access to the database

那不是一个伟大的架构

I assume that the db access will be via a controller

不需要 server-side,您可以将 DbContext 注入您的页面和组件

当您的组件强烈依赖于实体 类 和业务逻辑时,Razor Class 库可能不是最佳选择。

如果确实需要,请使用 storage-agnostic 模型和服务接口创建特定层。这是 the Onion architecture.

中核心的 2 层

您的组件可以依赖接口,主应用可以实现它们。