开发者

Entity Framework UnitOfWork

开发者 https://www.devze.com 2023-02-15 05:24 出处:网络
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

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 hav开发者_开发知识库ing it in the Repository Layer, that layer now needs a reference to System.Data.Entity. Bad or OK?


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.


Usually the implementation lies in the Repository layer for readability/understanding reasons. I don't find any issue with having your interfaces in the Domain Layer.

You can even have something similar as below

 - Domain
   ->Interfaces
   ->Repository
      -> Actual Implementation 

However as you said, it really doesn't matter where the actual implementation is. However -it is easy for others to understand the flow if you organize the structure properly.

0

精彩评论

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

关注公众号