实体框架工作单元
我正在 EF 4 中使用 UnitOfWork 模式,只是想知道 EFUnitOfWork 的实现应该放在哪里?它应该存在于存储库层吗?我的所有接口都在域层中。这听起来正确吗?
我正在使用 Ninject 通过 IUnitOfWork 注入存储库。
我想这真的不重要,因为您不会真正测试您的 EF 特定存储库,对吗?
另一种选择是让它存在于 EF 模型和上下文所在的数据层中。
通过将其放在存储库层中,该层现在需要对 System.Data.Entity 的引用。坏还是好?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
在 DDD 之后,您通常需要在解决方案中包含一个 ProjectName.Core 项目。该项目的结构如下:
ProjectName.Core ->存储库(全部
您的存储库接口)
ProjectName.Core -> DomainModel
ProjectName.Core ->基础设施-> IUnitOfWork(uow接口)
ProjectName.Core ->基础设施-> DtatAccess(存储库实现和所有
数据库相关文件包括uow实现)
有时,如果项目足够大,我会在我的解决方案中再添加一个名为 ProjectName.Infrastruct.DataAccess 的项目,并将所有 DataAccess 实现放在该项目中。
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
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.