存储库仍然是没有工作单元的存储库吗?

发布于 2024-07-17 06:10:03 字数 264 浏览 5 评论 0原文

如果您创建一个封装给定实体的所有持久性逻辑的存储库类(例如 PersonRepository),但您的存储库类没有实现工作单元模式或身份映射模式,那么它是否仍被视为存储库? 换句话说,存储库实现是否需要工作单元和身份映射,或者我们可以将封装持久性逻辑的任何类称为存储库吗?

我应该补充一件事。 如果存储库不需要这些模式并且它实际上只是持久性方法的容器,那么存储库和 DAO(数据访问对象)之间有什么区别? 我们是否只是为同一个对象创建多个名称,或者我们是否缺少存储库应有的部分内容?

If you create a repository class that encapsulates all of your persistence logic for a given entity, such as PersonRepository, but your repository class does not implement the Unit of Work pattern or the Identity Map pattern, is it still considered a repository? In other words, are Unit of Work and Identity Map required for a repository implementation, or can we just call any class that encapsulates our persistence logic a repository?

I should add one thing. If a repository does not require these patterns and it's really just a container for persistence methods, then what is the difference between a repository and a DAO (Data Access Object)? Are we just creating multiple names for the same object or are we missing part of what a repository is supposed to be?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(4

俏︾媚 2024-07-24 06:10:03

是的,它仍然是一个存储库。

至于如果Repository == DAO,我认为Repository应该位于业务逻辑层,而DAO应该位于数据访问层,即我认为它们位于不同的层。 据我了解,Repository 调用 DAO 方法来加载和保存数据。

Yes, it is still a repository.

As for if Repository == DAO, I think Repository should be on business logic layer and DAO should be on data access layer, i.e. I think they are on different layers. So as I understand, Repository calls DAO methods to load and persist data.

无人问我粥可暖 2024-07-24 06:10:03

我想说存储库和工作单元模式是正交的。

通常,我希望单个工作单元跨越多个存储库上的操作,因此其实现将属于更高层。

I'd say the Repository and Unit of Work patterns are orthogonal.

Very frequently, I want a single unit of work to span operations on multiple repositories, so an implementation of that would belong into a higher layer.

无名指的心愿 2024-07-24 06:10:03

根据 Sii 所说 - 如果存储库和工作单元不相关,对我来说似乎更好。 关注点分离?

Building on what Sii said - it seems better to me if the repository and the unit of work aren't related. Seperation of concerns?

虐人心 2024-07-24 06:10:03

在考虑关注点分离时,请记住您的存储库将具有数据存储实现方法,允许您将其排除在主代码之外。 这对于单元测试以及最终完全替换数据存储实现很有帮助(数据存储实现的一个示例是 ASP.NET 中的 LINQ-to-SQL。)

When considering separation of concerns, remember that your Repository will have the data storage implementation methods, allowing you to keep that out of your main code. This is helpful for unit testing as well as eventually swapping out your data storage implementation altogether (an example of a data storage implementation would be LINQ-to-SQL in ASP.NET.)

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