-1

This may be a dumb question, but I don't know how to solve this.

I am moving from CRUD to Domain-Driven Design with CQRS.

I have seen many DDD examples like this. You could find many more on Github.

The domain model has methods like changeDetails, addSomething, removeSomething, etc., and the commands could be just like that.

But in the UI, I have only 1 page with all its information, and everything is updated by clicking a single Save button.


How could I trigger all of the commands in 1 click?

If all commands are triggered and 1 fails, could the information be inconsistent?

2

1 Answer 1

3

Problem here is that your UI is CRUD Oriented instead of Task-Based. As you're already experiencing, it generates a lot of impedance between your backend / frontend tiers when utilizing rich domain models. So, you have several options here:

  1. Implement some kind of compare & set functionality with the desired entity state coming from the UI with respect what you have in the database, and then call the appropiate domain methods based on the comparation outcome.
  2. Consider implementing a PATCH operation including only these fields that have changed; This implies additional technical complexity depending on how you deal with serialization in your edge layer.

Please note that in both cases you will have to consider whether the order of domain call operations impact the final state of your objects.

3
  • From my experience, every single application has CRUD operations. What would you do to solve without complicating the problem? Nov 4, 2021 at 2:18
  • @NgọcNguyễn this is not completely true. Every domain can be modeled through CRUD resources, but in some cases this produces an overcomplicated design because behaviours there matter more than data, while you are centering your analysis on the latter. In some cases, behaviour and data have same importance, so maybe the piece you are missing is that your domain can be split in different bounded context, each of them either CRUD-based or rich-domain-based.... Nov 4, 2021 at 10:59
  • IMO I'd add one more point to @George's answer: you should be able to turn your "add/edit item" UI into a wizard made of several steps, each of them validating business rules or triggering policies that involve interaction with other actors Nov 4, 2021 at 11:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.