实体框架工作单元

发布于 2024-10-20 18:59:40 字数 276 浏览 1 评论 0原文

我正在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

无声静候 2024-10-27 18:59:40

在 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.

如此安好 2024-10-27 18:59:40

出于可读性/理解的原因,通常实现位于存储库层。我没有发现将接口置于域层有任何问题。

你甚至可以有类似下面的东西

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

但是正如你所说,实际实现在哪里并不重要。然而,如果你正确组织结构,其他人很容易理解流程。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文