Raise domain events from your entities. Dispatch them automatically after
SaveChanges.
Handle them with multiple handlers. Built on MediatR, integrated with EF Core.
public class Product : Entity
{
public Guid Id { get; private set; }
public string Name { get; private set; } = "";
public static Product Create(string name)
{
var product = new Product
{
Id = Guid.NewGuid(),
Name = name
};
// Raise event — dispatched after commit
product.RaiseDomainEvent(
new ProductCreatedEvent(product.Id, name));
return product;
}
}
A focused set of primitives for in-process domain events — without the complexity of Event Sourcing, Outbox Pattern, or distributed messaging.
Raise an event with a single line: RaiseDomainEvent(...). No ceremony.
Events are records — value-based equality, safe to pass around.
Events dispatch automatically after SaveChanges succeeds.
One event, many handlers. Add features without touching existing code.
Handler failures are logged, not rethrown. Your transaction stays safe.
Handlers only run when the database write actually succeeded.
Add the core package. Add the EF Core package if you use it.
dotnet add package Eventra.Core
dotnet add package Eventra.Core.EntityFrameworkCore
Events use record and inherit from DomainEvent.
public sealed record ProductCreatedEvent(
Guid ProductId,
string ProductName
) : DomainEvent;
Inherit from Entity and call RaiseDomainEvent.
public class Product : Entity
{
public static Product Create(string name)
{
var product = new Product
{
Id = Guid.NewGuid(),
Name = name
};
product.RaiseDomainEvent(
new ProductCreatedEvent(product.Id, name));
return product;
}
}
Events are dispatched after SaveChanges succeeds.
var product = Product.Create(request.Name);
_dbContext.Products.Add(product);
await _dbContext.SaveChangesAndDispatchEventsAsync(
_dispatcher, cancellationToken);
return product.Id;
Eventra.Core contains abstractions and base classes. No EF Core dependency. Eventra.Core.EntityFrameworkCore adds the integration — and depends on Core.
This separation means EF Core is entirely optional. The core package has no dependency on any data access technology.
IDomainEvent
Base contract for all events
Entity
Base class with RaiseDomainEvent
IDomainEventDispatcher
Dispatches events to handlers
SaveChangesAndDispatchEventsAsync
EF Core extension
1. Command Handler
Product.Create("Kopi")
└─► RaiseDomainEvent(ProductCreatedEvent)
2. DbContext
SaveChangesAndDispatchEventsAsync()
├─► SaveChangesAsync() ──► DB
├─► ClearDomainEvents()
└─► DispatchAsync()
3. Dispatcher
foreach evt in events:
└─► mediator.Publish(evt)
└─► Handlers (parallel)
Two packages. Pick what fits your stack.
Eventra.Core
required
Core abstractions, base classes, dispatcher. No EF Core dependency.
Eventra.Core.EntityFrameworkCore
optional
EF Core integration. Adds SaveChangesAndDispatchEventsAsync.
Eventra focuses on in-process domain events. It deliberately does not implement:
If you need these, consider EventFlow, Marten, or MassTransit.
Install the packages and start raising domain events in minutes.