jett
jett

Reputation: 997

DDD/CQRS : where to persist

We recently started developing apps using concepts from both DDD and CQRS (no Event Sourcing). I am still somewhat confused as where exactly to call the repository to persist my Aggregate Roots.

Do I do it inside Command Handlers or do I do it in the Event Handlers?

Upvotes: 4

Views: 1256

Answers (1)

David Masters
David Masters

Reputation: 8295

You do this inside your command handler. You save your domain objects as normal. Even if you are not using event sourcing as a means of persisting your domain entities, you will still need to fire events that your query service will subscribe to. The event handlers on the read side will then update de-normalised tables tailor made for the UI screens. So basically you have two sets of data access code: one for the domain, one for the query service (read side). Its less work if you make use of event sourcing to persist your domain entities...

Upvotes: 5

Related Questions