Skip to content

Search EricksonLopez.* Ecosystem

Type a library name, NuGet package ID, .NET type, or architectural concept to search across the portal.

Guides & Recipes — EricksonLopez.Events

Use IEnvelopeEventHandler<TEvent> (services.AddEnvelopeEventHandler<TEvent, THandler>()) when handlers need EventEnvelope<TEvent>.Metadata (CorrelationId, CausationId, TenantId) without polluting the domain event record.

Register services.AddEventMiddleware<TMiddleware>(lifetime). Note that in v2.0.0, singleton IEventMiddleware instances undergo an immutability check.

using System;
using System.Threading.Tasks;
using EricksonLopez.Events.Contracts;
using EricksonLopez.Events.Identifiers;
using EricksonLopez.Events.Testing;
using Xunit;
namespace Example.EventsTests;
public sealed record AccountCreated(Guid AccountId) : IDomainEvent
{
public EventId Id { get; } = EventId.New();
public DateTimeOffset OccurredAt { get; } = DateTimeOffset.UtcNow;
}
public sealed class AccountEventTests
{
[Fact]
public async Task PublishAsync_WhenEventIsValid_CapturesPublishedEvent()
{
var publisher = new FakeEventPublisher();
var evt = new AccountCreated(Guid.NewGuid());
await publisher.PublishAsync(evt);
Assert.Single(publisher.PublishedEvents);
}
}