Quantcast
Channel: URF - Unit of Work & (extensible/generic) Repositories Framework
Viewing all articles
Browse latest Browse all 1539

New Post: Multiple Entity Framework Contexts(Multiple database types) on the same time.

$
0
0
You could also make your life a little simpler and actually use different interfaces for each unit of work. Don't be afraid to extend the framework.

To me the below code would be very expressive; it would convey your intent perfectly. But even better: your DI setup code for production and testing will become a lot less confusing. It also matches what you are actually doing: you are using the IDataContextAsync contract but you are applying to two separate underlying data stores - same contract, different roles.

I didn't go so far as to extend the IRepositoryProvider as well (which you would need to do) or in fact test this, but I think it should work ...
public interface IDataContextTeste1 : IDataContextAsync { }
public class DataContextTeste1 : DataContext, IDataContextTeste1
{
    public DataContextTeste1() : base("connStringTeste1") { }
}

public interface IDataContextTeste2 : IDataContextAsync { }
public class DataContextTeste2 : DataContext, IDataContextTeste2
{
    public DataContextTeste2() : base("connStringTeste2") { }
}

public interface IUnitOfWorkTeste1 : IUnitOfWorkAsync { }
public class UnitOfWorkTeste1 : UnitOfWork, IUnitOfWorkTeste1
{
    public UnitOfWorkTeste1(IDataContextTeste1 dataContext, IRepositoryProvider repositoryProvider) 
        : base(dataContext, repositoryProvider) { }
}

public interface IUnitOfWorkTeste2 : IUnitOfWorkAsync { }
public class UnitOfWorkTeste2 : UnitOfWork, IUnitOfWorkTeste1
{
    public UnitOfWorkTeste2(IDataContextTeste2 dataContext, IRepositoryProvider repositoryProvider)
        : base(dataContext, repositoryProvider) { }
}

Viewing all articles
Browse latest Browse all 1539

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>