Skip to content

Instantly share code, notes, and snippets.

@PilotBob
Last active October 9, 2023 22:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save PilotBob/803025d415b7e6794fb7149bb613172f to your computer and use it in GitHub Desktop.
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
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