This is my understanding about DDD at the moment:
- The strict repository pattern should only implement get(), delete() and create(), and maybe variants of get() where one can search or to retrieve an entire collection
- It is common for each aggregate root to have one repository
(from research, I know those are not universally accept norms)
The question here is how to implement complex queries which involves many aggregate roots. For example, we have two aggregate roots - product and user. If I am doing a page which list what products a user have bought, then I have a query which stretch across both the user aggregate and the product aggregate.
How should this query be implemented?
What I am doing now is actually to have a repository for this query and queries with related functionality (some will disagree and say the repository is not a query layer).
Use only the repository for product and user, grab all records and do everything in memory (this sounds wrong)
Have the query (LINQ or SQL) to be inside the service, not using the repository associated with the aggregates at all.
Are there some other ways?