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.
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)?
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.
To me, each repository is responsible for counting its elements, it's one method among getById, getAll... (standard methods).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With