开发者

Is it possible to add multiple DbContext Factories for the same DbContext to the services collection?

开发者 https://www.devze.com 2022-12-07 19:43 出处:网络
Is it possible to add more than 1 DbContextFactory, for the same DbContext, to the services collection in an ASP.NET Core application?

Is it possible to add more than 1 DbContextFactory, for the same DbContext, to the services collection in an ASP.NET Core application?

For example, I am trying the following code ...

services
  .AddDbContextFactory<WibWorkspaceContext, WibWorkspaceContextFactory>();

services
  .AddDbContextFactory<WibWorkspaceContext, WibWorkspaceSystemContextFactory>();

I want two different factories for the same DbContext. One factory always signs in using a SQL "admin" account and the other uses user-specific accounts.

I can't seem to figure out how to get this to work, though. How can I specify which one to use on the side of things that grab the service? For example, here's a constructor receiving the service - how does it know which one to use?

public async Task Invoke(HttpContext httpContext, IDbContextFactory<WibWorkspaceContext> contextFactory, IConfigu开发者_开发技巧ration configuration)

Is this possible? Thanks.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号