Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Entity Framework UnitOfWork

I am using the UnitOfWork pattern with EF 4, and was just wondering where the implementation of the EFUnitOfWork should live? Should it live in the Repository Layer? I have all of my Interfaces in the Domain Layer. Does this sound correct?

I am using Ninject to inject the Repositories with a IUnitOfWork.

I guess it really doesn't matter as you are not going to really test your EF specific repositories right?

The other option is to have it live in the Data Layer where the EF models and context are.

By having it in the Repository Layer, that layer now needs a reference to System.Data.Entity. Bad or OK?

like image 755
Sam Avatar asked Nov 29 '25 03:11

Sam


1 Answers

Following DDD, you generally want a ProjectName.Core project in your solution. In that project would be structured as follows:

  • ProjectName.Core -> Repository (all your repository interfaces)

  • ProjectName.Core -> DomainModel

  • ProjectName.Core -> Infrastructure -> IUnitOfWork (uow interface)

  • ProjectName.Core -> Infrastructure -> DtatAccess (repository implementations and all the database related files Including uow implementation)

Some times if the project is large enough, I will add one more project to my solution called ProjectName.Infrastructure.DataAccess and place all the DataAccess implementations in that project.

like image 85
Paul Avatar answered Dec 02 '25 02:12

Paul