my problem is about updating an entity related with the aggregate root. I have a Shipping class and my command is SetShipmentAsDelivered. Shipment has a relation with the Order class. So when the shippent is delivered I should mark the order as delivered.
My flow is like this;
So far I've no problem. But for the requirement mark the order as delivered I have to map all Order entity inside the ShipmentModel (like shipmentModel.Order.SetStateDispatched) which seems so redundant because all I need is making an update at one field for the related entity "Order". Should I just seperate to save operations and create the Order class out of the Shipment? What is the best way to handle such scenario?
Thank you.
You can use domain events.
So the use case that updates the shipment can emit an order shipped event.
In the order component you can implement an domain event listener that receives the event and executes the order update use case.
The MarkOrderShipped use case is independent from the way it is triggered. It might be the domain event listener or a controller that is invoked as a result of a user action.
I published an example application in Java that uses an domain event bus to synchronize different components. It doesn't matter if that domain event bus is a local kind of synchronous event delivery mechanism, an asynchronous local or a message queue or something else.