Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 404
jett Avatar asked Sep 14 '25 19:09

jett


1 Answers

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...

like image 50
David Masters Avatar answered Sep 17 '25 19:09

David Masters