I'm stuck with one problem and I don't know what should I do.
My domain:
I've a Booking entity, root of the booking business context.
Inside the Booking exist the collection of Event(s), that is the list of real events created by the user. Booking looks a bit useless, but the whole system links the Booking to other entities, so it's really the root of the business.
An Event could have text notes, hence I've created a Notes entity. I use an entity because the notes could change in the time, they're linked to an Event and cannot be shared. Notes actually are bound inside the booking business context and aggregated to the Booking root entity.
Form (create event):
I've a form used to submit "Events". Actually, the data of the form generates a command with all the information that's needed to create a new Event and, if the user wants, its Notes.
Command (create event):
From the form a command is created and sent to the server. The command has the data of the event.
The handler, on the server, operates on the main entity, Booking, creating a new Event. The Event could have or not Notes, according to what the user has put in the form.
Other commands that the booking business context handles are:
- delete an event
- cancel an event (creates a special event for events that cannot take place), in future it could be used also to add a note (why the event was cancelled)
- create a backup event for events cancelled
Another command, that's actually inside this context, is
- update notes for an event
Here comes my question:
being able to be changed without having to deal with Event, could Notes be promoted as root entities and have they're business context? So, I'll end up with one context for Bookings and one for Notes.
Actually, to change the Notes and stay in the DDD context, hence don't expose too much, I've to make some "jumps" to execute the changes. It works, yes, but it's ugly. Maybe it's much more elegant, and bounded to the right contexts, if I split the things.
On the other side, if the answer is yes, how could I handle the first command, that generates the Event with the Notes? The same question would apply for the cancel.
I cannot fire two commands from the form, one depends from the other so the sequence is important.
It's also hard to create an handler (a event listener, at the end) that, after the create/cancel are successfully completed, it fires a second command to change the Notes. How can I identify the right Event? The listener must be created with the data sent by the form, to match the event to handle.