how to use multi DBContextPool?

前端 未结 2 1425
自闭症患者
自闭症患者 2021-01-21 06:05

In EFCore 2.0 Add new feature, DbContext pooling. i know how to use it in single context, however, sometimes need multi context in project,

public class BContext         


        
2条回答
  •  Happy的楠姐
    2021-01-21 06:28

    Or you can register your own factory of DbContextPool

    services.AddDbContextPool(options =>
    {
        options.UseInMemoryDatabase("AContext.InMemory");
    });
    services.AddDbContextPool(options =>
    {
        options.UseInMemoryDatabase("BContext.InMemory");
    });
    
    collection.AddSingleton(svcs => new DbContextPool(svcs.GetService>()));
    collection.AddSingleton(svcs => new DbContextPool(svcs.GetService>()));
    

提交回复
热议问题