1
votes

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.

1
I don't understand what you mean by "context", is it "bounded context" from DDD?Constantin Galbenu
Yes, I've just used the wrong name. Bounded context, instead of business context.Luca Masera

1 Answers

2
votes

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.

From what I understand, there are no invariants that Booking aggregate root must protect. Even if an Event belong to a Booking if there are no rules that state that some combination of events should not exist then Event should be also an Aggregate root.

So, the CreateEventCommand should contain the BookingId, EventId and an optional notes.

Notes actually are bound inside the booking business context and aggregated to the Booking root entity

I don't quite agree with this. Notes belong to an Event and an Event belongs to an Booking so it is normal that a Note is linked to a Booking but there are no invariants that link a Note to a Booking, only the association by ID which is permitted by the DDD in any case.

could Notes be promoted as root entities and have they're business context?

Yes, if there are no invariants that must be protected by the Event AR. Then, the CreateNewNoteCommand should contain the BookingId and the EventId.

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.

Indeed, the design gave you a feedback that you did it wrong. If you design your Aggregates right then this situation should not occur. If things seem to become very complicated then go back and rethink your design. DDD is much about refactoring.