In-memory event bus for modular monolith .NET applications, suitable for simple event-driven communication, development, and testing.
$ dotnet add package Mubai.EventBus.InMemoryEnglish | 简体中文
In-process, in-memory event bus for modular monoliths or local development/testing. Events are dispatched synchronously to handlers registered in the current process. No persistence, no cross-process capability.
PublishAsync executes all handlers in-call.EventNameAttribute; falls back to the event type name.IServiceProvider with a scoped lifetime per handler invocation.Reference the Mubai.EventBus.InMemory package (or project reference inside the solution).
// Event
public record OrderCreated(Guid OrderId) : IntegrationEvent(OrderId, DateTimeOffset.UtcNow);
// Handler
public sealed class OrderCreatedHandler : IIntegrationEventHandler<OrderCreated>
{
public Task HandleAsync(OrderCreated @event, CancellationToken ct = default)
{
// business logic
return Task.CompletedTask;
}
}
// Registration
services.AddInMemoryEventBus();
services.AddIntegrationEventHandlersFromAssemblyContaining<OrderCreatedHandler>();
// Publish
await eventBus.PublishAsync(new OrderCreated(orderId), ct);
[EventName("InventoryReserved")]
public record InventoryReservedEvent(Guid OrderId) : IntegrationEvent(OrderId, DateTimeOffset.UtcNow);
Publisher and subscriber must use the same event name; if the attribute is omitted, the type name is used.