I'm struggling with the concept of repositories for queries #963
Unanswered
renetitulaer
asked this question in
Q&A
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Reading about DDD, my conclusion is that DDD is especially interesting for commands, not queries (in CQRS).
Invariants only have meaning in the context of commands so when you create/update/delete entities.
In the context of DDD we have aggregates. In the context of queries we don't. Within DDD, an order has only a reference to the customer id (most often). For queries it makes sense that an order has a reference to the customer so we can display the name of the customer.
When I want to use Ardalis specifications, the entity should implement IAggregateRoot but for queries (when specifications are especially useful), I don't want to know about repositories. Wouldn't it make more sense to decouple specifications from repositories.
Maybe a repository should even only support loading one aggregate. For create/update/delete, a repository applies to one entity. Maybe this should also apply to read, only read one entity by a key (alternate keys allowed).
Next to the repository there should be a factory or QueryService. A QueryService operates on a collection of entities. Which could be aggregates but they don't have to be, for example an Order model with a customer property.
I'm curious how you think about this.
Beta Was this translation helpful? Give feedback.
All reactions