总根的通用Vs个人存储库

编程入门 行业动态 更新时间:2024-10-22 12:27:30
本文介绍了总根的通用Vs个人存储库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

据我了解,绑定上下文可以具有模块,模块可以具有许多聚合根,聚合根可以具有实体。为了保持持久性,每个聚合根都应该有一个存储库。

As I understand, the Bounded Context can have modules, the modules can have many aggregate roots, the aggregate root can have entities. For the persistence, each aggregate root should have a repository.

由于大型项目中有多个聚合根,因此可以使用通用存储库 strong>,一种仅准备就绪,另一种仅更新?或应该为每个聚合根具有单独的存储库,以提供更好的控制。

With the numerous aggregate roots in a large project, is it okay to use a Generic Repository, one for ready only and one for update? Or should have separate repository for each aggregate root which can provide better control.

推荐答案

在大型复杂项目中,我不会建议使用通用存储库,因为除了基本的 GetById(), GetAll()外,还有很多其他特殊情况...操作。

In a large complex project, I wouldn't recommend using a generic repository since there will most likely be many specific cases beyond your basic GetById(), GetAll()... operations.

Greg Young撰写了一篇有关通用存储库的精彩文章: codebetter/gregyoung/2009/01/16/ddd-the-generic-repository/

Greg Young has a great article on generic repositories : codebetter/gregyoung/2009/01/16/ddd-the-generic-repository/

可以使用通用存储库,一个仅用于准备就绪,一个用于更新吗?

is it okay to use a Generic Repository, one for ready only and one for update?

存储库通常不处理对实体的保存更新,即,它们没有 Update(EntityType实体)方法。通常由您的ORM的变更跟踪器/工作单元实施来解决。但是,如果您要查找将读写与读写分开的体系结构,则绝对应该查看 CQRS 。

Repositories generally don't handle saving updates to your entities, i.e. they don't have an Update(EntityType entity) method. This is usually taken care of by your ORM's change tracker/Unit of Work implementation. However, if you're looking for an architecture that separates reads from writes, you should definitely have a look at CQRS.

更多推荐

总根的通用Vs个人存储库

本文发布于:2023-11-28 16:31:50,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1643141.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!