C
C#4w ago
taner.

'Entity' base class with 'DomainEvents'

I have seen many people using the 'Entity' base class for EFC models with 'DomainEvents'. I wanted to know its purpose and, in general, what it does.
No description
2 Replies
Sossenbinder
Sossenbinder4w ago
So I think overall the aim is to use domain events to propagage behavior between multiple entities When it comes to why they would just place them in a list, that's a good question to be honest I could imagine the goal is to have multiple events in the scope of a transaction without immediately forwarding them to e.g. a database transaction to allow tests to just grab the List<T> (and also to make sure the events are applied in the scope of a domain "transaction", not just rolling to the database in the middle of it) And then applying all the events prior to writing it to the database
taner.
taner.OP4w ago
So what i found it is, when an event is triggered in an entity, it is stored in a list of domain events. Before saving changes to the database, these events are collected. After the transaction is successfully committed, the events are dispatched, usually via an event bus or mediator. Basically like you said.

Did you find this page helpful?