Last active
October 9, 2023 22:00
-
-
Save PilotBob/803025d415b7e6794fb7149bb613172f to your computer and use it in GitHub Desktop.
Domain Events are raised by Entities, Sent by Unit of Work, Integration Events are published by UseCases
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
DoThisThingCommandHandler() | |
{ | |
var entity = entityrepo.GetEntity(); | |
entity.DoThisThing(); // raises domain event | |
unitOfWork.Save(); // publishes the domain events | |
_bus.Publish(new ThisThingIntegrationEvent(entity.id, entity.payload, blah)); | |
} | |
class Entity : AggregateRoot | |
{ | |
public void DoThisThing() | |
{ | |
// some manipulation of the entity | |
this.RaiseEvent(new ThisDomainEvent(this.id)); | |
} | |
} | |
class unitOfWork | |
{ | |
// raise the events before saving | |
var events = _dbContext.GetAllRaisedEvents(); | |
foreach (var event in events) | |
{ | |
_mediatr.Send(event); | |
} | |
_dbContext.SaveChanges(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment