CQRS has got me into thinking mode.. I am tryinng to start a new project with CQRS ideas. The main things that I like is
1) the separation of Query and Command. Our Domain queries have been a problem.
2) Using Event Storage for Audit - I wont be using it for Replay - AT least not now.
I am good with the query side and I still have some questions on Domain Events
If a Command results in updation of Multiple Aggregates Roots( Ex. Order and OrderDetail) I will have the them scoped under UnitofWork ( transactional). Now each domain is responsible for publishing events when a change takes place to its state.
let us say the command changes 3 orderDetail records. Each OrderDetail will publish 2 Events. In the end we have 6 events .
a) If I publish the events as soon as I have made the changes to the domain object ( but not committed the transaction) how do I reverse the events that have been published (and may have been consumed by subscribers)
- What I can think of is to hold the events to be published in a list 'under the same unit of work scope' and once the committ on transaction has been called, store it and publish it . Does this sound something one would do.
b) If the changes in OrderDetail requires that some change also take place in Order Aggregate Root then
i) Should I base those changes by handling the events published by OrderDetail Aggregate ? For ex. let us say two Order Detail were removed. This makes Order status from "preferred" to "Not preferred" .
ii) What if the Event errors and does not update order state - If order remains preferred then it gets shipped in 2 days.
Adding another question
c) Are "Domain events are the source of all application state changes" or are they "Result of all application state changes"
Thank you in Advance,
The Mar