Skip to content

When to use a 'Specification' vs when to a 'Query Service'? #722

Answered by ardalis
nabeelfarooqui98 asked this question in Q&A
Discussion options

You must be logged in to vote

Yes the existence of query objects in the template is meant to demonstrate that you're not bound by some rule that says all data access must be through specifications - or even repositories. Instead, especially if you're able to take advantage of Command-Query-Responsibility-Segregation (CQRS), you can use different approaches where appropriate.

  1. When you need domain objects because you're enforcing domain rules (usually when you're making changes and mutating state), you probably want to use the Repository pattern possibly along with Specifications.
  2. When you just need some simple (read only) data and Repository/Specification can provide it with minimal effort, you can still use these pat…

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@nabeelfarooqui98
Comment options

Answer selected by nabeelfarooqui98
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants