开发者

EF Repository library for multiple db contexts

开发者 https://www.devze.com 2023-03-16 15:36 出处:网络
Anyone suggest me how to build an EF repository pattern that supports multiple contexts (more than one Db context each one belongs to a separate DB.).

Anyone suggest me how to build an EF repository pattern that supports multiple contexts (more than one Db context each one belongs to a separate DB.).

R开发者_运维知识库egards, Hareen.


Use a dependency injection framework to inject the Contexts for your repositories.

public class FooRepository
{
  FirstContext _fc;
  SecondContext _sc

  public FooRepository(FirstContext fc, SecondContext sc)
  {
     _fc = fc;
     _sc = sc;
  }
}

public class BarRepository
{
  FirstContext _fc;
  SecondContext _sc
  ThirdContext _tc

  public BarRepository(FirstContext fc, SecondContext sc, ThirdContext tc)
  {
     _fc = fc;
     _sc = sc;
     _tc = tc;
  }
}
0

精彩评论

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