Redeon.SuperSiteEngineCore.Web.Eltheon.Core.Features.Events
In-process EventBus for Eltheon v2. Ships the core contracts (IEvent, IEventBus, IEventProvider, IEventTransport), a default in-process bus, bounded in-memory transport, and an event registry. Goal: publish business events consistently and decouple features (Notifications, SignalR, Logging).
Scope: In-process only. External brokers/webhooks belong in follow-up features.
Install
dotnet add package Redeon.SuperSiteEngineCore.Web.Eltheon.Core.Features.Events
DI-Setup
builder.Services.AddEltheonEvents(
bus => {
bus.DispatchMode = EventDispatchMode.Sequential; // oder Parallel
bus.ErrorMode = EventErrorMode.ContinueOnError; // oder StopOnFirstError
},
transport => {
transport.Capacity = 1_000;
transport.FullBehavior = TransportFullBehavior.DropOnFull; // ThrowOnFull / WaitWithTimeout
});
Publish & Subscribe
public sealed record UserCreatedEvent(string UserId, string Email) : IEvent
{
public string EventName => "User.Created";
public DateTime OccurredAtUtc { get; } = DateTime.UtcNow;
public string? Source => "Identity";
public string? CorrelationId { get; init; }
public string? Category => "UserLifecycle";
}
public sealed class NotificationEventProvider : IEventProvider
{
public Task HandleAsync(IEvent @event, CancellationToken ct = default)
{
if (@event.EventName == "User.Created")
{
// Notification erzeugen ...
}
return Task.CompletedTask;
}
}
// Usage in feature code
await _eventBus.PublishAsync(new UserCreatedEvent(user.Id, user.Email));
Transport & Registry
- Transport:
InMemoryEventTransportis bounded; behavior on full buffer is configurable (Drop/Throw/Wait). Suitable for later background services. - Registry:
InMemoryEventRegistrystores metadata (EventMetadata) and can feed logging/metrics. Seed viaIEventRegistry.Register(...)or DI. - Metrics: If the Metrik feature is registered, published events increment
eltheon_events_publish_total{event,category,severity,success,providers}. The in-memory history buffer size is also exported aseltheon_events_history_size.
Tests
Redeon.SuperSiteEngineCore.Web.Eltheon.Core.Features.Events.Test covers dispatch error paths (Continue/Stop) and transport enqueue/dequeue. Add further tests for cancellation/timeouts as needed.