Part of DKNet.EfCore.Abstractions. Entity<TKey> implements IEventEntity with separate queues for event objects and event types.
Use the console-project setup in the Quick Start, then replace Program.cs with this example.
using DKNet.EfCore.Abstractions.Entities;
using DKNet.EfCore.Abstractions.Events;
var order = new Order();
order.Place();
Console.WriteLine(order.GetEvents().Events.Length); // 1
order.ClearEvents();
Console.WriteLine(order.GetEvents().Events.Length); // 0
public sealed class Order : Entity
{
public void Place() => AddEvent(new OrderPlaced(Id));
}
public sealed record OrderPlaced(Guid OrderId) : EventItem;
AddEvent(object) records the supplied object. AddEvent<TEvent>() records a type to map from the entity later. GetEvents() returns array copies and does not drain either queue.
There is no DI setup or options object in this package. EventItem supplies a case-insensitive AdditionalData dictionary, excluded from JSON, and an EventType based on the runtime full type name. IEventItem is the matching contract.
IEventPublisher declares single and batch PublishAsync methods with a default cancellation token. DefaultEventPublisher implements the batch as a sequential loop over your single-event override.
Domain methods queue events through IEventEntity. Events consumes those queues in the Hooks pipeline and calls the host IEventPublisher adapters; Abstractions has no transport dependency.
MapsterMapper.IMapper at dispatch time; the object overload does not.