Take an example of sales orders (modelled by a SalesOrder AR). If you ask your domain experts "what happens when you delete an order?" they'll likely respond "Oh no - you can't delete orders!" followed by "although you can cancel them or complete them, in which case you can't add any more line items.". In this example "completed" and "cancelled " are the key words, and you'd implement the appropriate invariants in your SalesOrder AR. Of course that implementation may end up as a state machine, but then it's often the case that an AR works like a state machine (i.e. favour a variable "state" rather than a heap of boolean flags).
--
You received this message because you are subscribed to the Google Groups "DDD/CQRS" group.
To unsubscribe from this group and stop receiving emails from it, send an email to dddcqrs+u...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
Thanks :) What if I'm not using ES, but use ORM, and I want to notify that a BlogPost is deleted. I can simply delete the blogpost by repository.Delete(post) in the command, but where is the best place to raise BlogPostDeleted event? Call blogpost.MarkDeleted() which raise BlogPostDeleted before repository.Delete(post)?
You received this message because you are subscribed to a topic in the Google Groups "DDD/CQRS" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/dddcqrs/S1D650oJBDs/unsubscribe.
To unsubscribe from this group and all its topics, send an email to dddcqrs+u...@googlegroups.com.
Thanks :) What if I'm not using ES, but use ORM, and I want to notify that a BlogPost is deleted. I can simply delete the blogpost by repository.Delete(post) in the command, but where is the best place to raise BlogPostDeleted event? Call blogpost.MarkDeleted() which raise BlogPostDeleted before repository.Delete(post)?
Yea, i wanted to move in small steps before cos I don't have ES experience in real projects. So afraid to use it currently. :(
Sounds like you’ll run into model mismatch at some point soon using that kind of system :-)
Thanks :) What if I'm not using ES, but use ORM, and I want to notify that a BlogPost is deleted. I can simply delete the blogpost by repository.Delete(post) in the command, but where is the best place to raise BlogPostDeleted event? Call blogpost.MarkDeleted() which raise BlogPostDeleted before repository.Delete(post)?
Looks like soft delete is better because I can raise event in aggregate root like others. I do feel the pain of ORM + events. But I don't have real project ES experience, so want to move in small steps so it's easier to control.
What about document db/no sql + events?
By problems you mean the same event can be fired twice if trn fails?
You can do the following for events+ORM:
1. Your repository should have Get and Save only, no add/update/delete
2. Your AR base class should track AR state, such as Created, Loaded&Changed, Deleted
3. AR base class should have protected MarkAsDeleted method, which will set AR state to Deleted
4. Your AR should have Delete method which will fire event + call MarkAsDeleted of base class
5. Your repository in Save method should read the AR's state and execute corresponding insert/update/delete of the ORM.
Nice idea. +1
Also for the consistency of ORM writes and events publishing (aka 2pc), when events are being published from AR, they should be just accumulated in the AR base class, and in the repository, when you have already saved data to DB but not commited transaction yet, you could get pending events from AR and publish them to SB. This is not real 2pc, but might be enought for your needs.
As i said it is not 2pc :), but as you usually say "what are the chances for the issue to happen, to prevent it now instead of fixing its conciquencies when it happens". I would not use ORM if that was my decision, but the life is tough :).