mardi 4 août 2015

Having hard time with generic repository and Unit of work on multiple databases

I'm trying to solve this puzzle for a long time now. I have a .Net 3.5 Webforms project at work. I want to make use of Linq-to-SQL and implement a Data Access Layer based of it. But the problem is that we have 3 SQL-Server databases (same server).

  1. Client Database. -> 1 Per client.
  2. Project Database. -> 1..* Per client. //Changes on the fly depends on a user selection at the main screen.
  3. Information Database -> Shared by all clients. (Read only data, mostly lookup tables).

I started to build my architecture but came across a problem, how would I create one UnitOfWork shared between 3 different DataContexts (1 per database).

Here is a UML I made so far, I want my UOW class to be able to do the next code seamlessly

IUnitOfWork uow = new UnitOfWork(::pass context here ??::)
IRepository<Client> clientRepository = Uow.GetRepository<Client>(); // From Client DB
IRepository<Account> accountRepository = uow.GetRepository<Account>(); //From Projects DB

Here is my design:

Data Access Layer

I'd appreciate any serious help. And also any kind of comments good or bad about my approach and also contact me via linked-in if you are keen to help me sort things out.

Aucun commentaire:

Enregistrer un commentaire