总根的通用Vs个人存储库 [英] Generic Vs Individual Repository for Aggregate Root

查看:57
本文介绍了总根的通用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撰写了一篇有关通用存储库的精彩文章: http://codebetter.com/gregyoung/2009/01/16/ddd-the-generic-repository/

Greg Young has a great article on generic repositories : http://codebetter.com/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个人存储库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆