DDD中的存储库类 [英] Repository class in DDD

查看:116
本文介绍了DDD中的存储库类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试关注DDD,我有一个Question类和一个Feedback类(等等)。我希望能够计算问题的数量,反馈的数量以及许多其他被视为元操作的事情。

I am trying to follow DDD and I have a Question class and a Feedback class (among others). I want to be able to count the number of questions, number of feedbacks and many other things which is considered meta operations.

这种元方法是否应该相同存储库作为属于该类的其他方法,或者它们应该位于MetaRepository中,您在其中使用不同的元方法查询数据库(在这种情况下,所有类都将混合使用)?

Should such "meta" methods be in the same repository as the other methods belonging to the class, or should they be in a MetaRepository where you have different meta methods that queries the database (in this case all classes will be mixed)?

推荐答案

DDD中没有任何内容禁止每个聚合使用多个存储库。您可以简单地为基本查询和生命周期方法(IQuestionsRepository)创建一个存储库,并为您称为元或统计目的的单独存储库(IQuestionsStatistics)。这适用于较大的域,其中 one-repository-per-aggregate 原则可能导致方法爆炸和SRP违规。以下DDD不应违反基本的OOP原则。

Nothing in DDD prohibits having more than one repository per aggregate. You can simply have one repository for basic queries and lifecycle methods (IQuestionsRepository) and a separate repository for what you call 'meta' or 'statistics' purposes (IQuestionsStatistics). This works very well for a larger domains where following one-repository-per-aggregate principle may result in 'method explosion' and SRP violation. Following DDD should not go against basic OOP principles.

这篇关于DDD中的存储库类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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