EF Repository library for multiple db contexts
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;
}
}
精彩评论