I know it has been a long time, i was finishing some work, Can we talk about << domain events >> today ? 😄
A - What, When, Why ? 🤔
A - 1 - What is a Domain Event ?
There is no direct definition, we can say that they are the result of listening to domain experts. And the final point is something happened and the domain experts want to know it.
A - 2 - When to use Domain Event ?
We have to go for it
How can we determine if something that happens in the domain is important to the domain experts? As we have discussions with them, we must listen carefully for clues. Consider a few key phrases to listen for when domain experts talk:
• “When . . .”
• “If that happens . . .”
• “Inform me if . . .” and “Notify me if . . .”
• “An occurrence of . . .”
A - 3 - Why use Domain Event ?
Because if something happened in the domain, those who want to know it are not neccessarily in the domain, so we use domain event like a bridge to process the new to others.
This tends to happen when Events must be broadcast to external
services, where the systems in your enterprise have been decoupled and occurrences throughout the domain must be communicated across Bounded Contexts (2). Events like this get published, and subscribers are notified. As such Events are handled by subscribers, they may have far-reaching impact on local and remote Bounded Contexts.
B - Modeling Domain Event ? 🦾
B - 1 - The Name of the Domain Event
I think we are clean coders 👀 and futhermore we are in domain driven design. So the name should be in the norm of the ubiquitous language. And i totally agree when in the book, it says :
If an Event is the result of executing a command operation on an Aggregate, the name is usually derived from the command that was executed. The command is the cause of the Event, and hence the Event’s name is rightly stated in terms of the command having occurred in the past.....When publishing Events from Aggregates, it is important that the Event name reflect the past nature of the occurrence. It is not occurring now. It occurred previously. The best name to choose is the one that reflects that fact
B - 2 - Properties of the Domain Event
Firstly because it is an event :
For one, we need a timestamp that indicates when the Event occurred.
And for the other properties it all depends on the talk :
the team determines what other properties are necessary to
represent a meaningful occurrence of what happened. Consider including whatever would be necessary to trigger the Event again. This normally includes the identity of the Aggregate instance on which it took place, or any Aggregate instances involved. Using this guidance, we might create properties of any parameters that caused the Event, if discussion proves they are useful. It’s also possible that some resulting Aggregate state transition values could be helpful to subscribers.
B - 3 - Domain Event and Aggregate Characteristics
Inside the aggregate as the result of the process, inside the aggregate we can create an event and of course it would contain some properties of the aggregate source:
Events are designed to be created by direct request from clients.
This is done in response to some occurrence that is not the direct result of executing behavior on an instance of an Aggregate in the model. Possibly a user of the system initiates some action that is considered an Event in its own right. When that happens, the Event can be modeled as an Aggregate and retained in its own Repository. Since it represents some past occurrence, its Repository
would not permit its removal. When Events are modeled in this way, like Aggregates they become part of the model’s structure. Thus, they are not just a record of some past occurrence, although they are that also. The Event is still designed as immutable, but it may be assigned a generated unique identity.
N.B: : An unique identity because there will be times where we have to compare event and here an unique identity is required
Soooooo 😊 in this article we have clearly define the what, when, and why of a domain events and how the modeling part works !
See yoouuu in the next one 😊
Top comments (0)