c# - 如何使用 Autofac 注册 DbContextPool?
问题描述
微软的 DI 有AddDbContextPool
,但是怎么做呢Autofac
?
解决方案
因此,我猜想,“如何注册 Microsoft 的 DI(日志记录、DbContext 等)中存在的内容? ”之类的标准解决方法是使用ServiceCollection
然后调用Populate
方法。
我的实现DbContextPool
:
public static void RegisterDbContextPool<T>(this ContainerBuilder builder, Action<DbContextOptionsBuilder> options) where T : DbContext {
var serviceCollection = new ServiceCollection();
serviceCollection.AddDbContextPool<T>(options);
builder.Populate(serviceCollection);
}
推荐阅读
- php - 使用谷歌图表构建数据透视表
- ios - UIMenuController 未显示
- java - 从某个键的映射中获取值并将其作为另一个条目集添加到另一个映射中
- javascript - 在视频背景上添加静音/取消静音按钮 [DIVI 主题 - WordPress]
- asp.net-mvc - ASP.NET MVC 生命周期中的慢进程
- c# - 如何在不影响数据库的情况下从 GridView 中删除一行
- linux - 在 Linux 中将相关的数据行分组到单个列中
- javascript - 用于将值从一张表复制到另一张表的 Google Apps 脚本
- ios - UINavigationController:navigationController:willShowViewController:animated:从未调用
- python - 以次要 y 轴和 x 轴为日期的图表