[英]How to register DbContextPool using Autofac?
Microsoft 的 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);
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.