What problem does it solve?
Prevents lost or inconsistent domain events by ensuring events and outbox messages are persisted atomically and published reliably to a message broker, eliminating race conditions between database commits and external publishing.
Core Features & Use Cases
- Atomic persistence: Save domain events and OutboxMessage records together via IUnitOfWork and a single SaveChangesAsync call.
- FK-based outbox: OutboxMessage wraps an Event via a navigation property (shared primary key) rather than serializing event bodies.
- Reliable publisher: Singleton ServiceBusPublisher uses Task.Run, a lock and a lockedScopes counter, creates a DI scope for DB access, reads in batches of 200, publishes each message, removes it, and saves to guarantee at-least-once delivery.
- Use Cases: Order management events, cross-service integration, audit/event sourcing scenarios in .NET microservices using Azure Service Bus.
Quick Start
Use the outbox skill to implement a CommitEventService that saves events and matching OutboxMessage entities in one SaveChangesAsync call and then triggers the singleton ServiceBusPublisher to publish them.