Shared services
Integration events and the outbox
Publish durable integration messages and understand their transaction, tenant and retry behavior.
Separate domain events from integration events
Domain events belong to entity behavior inside the application. Integration events expose a stable fact for another consumer. The framework's Eventing.Abstractions project defines IIntegrationEvent, IIntegrationEventHandler<T>, IEventBus and IOutboxWriter so modules can work against contracts.
Use an integration event when another module should react after a meaningful business change. Do not replace a required immediate response with an asynchronous event unless the caller can handle pending work and eventual completion.
Register infrastructure once
The API and migrator call AddEventingCore once. One framework-owned EventingDbContext owns outbox and inbox persistence. A module registers its consumers through AddIntegrationEventHandlers(typeof(MyModule).Assembly) using its actual module type.
Do not recreate per-module outbox stores. The current design intentionally avoids resolving whichever store happened to be registered last. The migrator also includes eventing's initializer so the required tables are created with the rest of the schema.
The default provider is InMemory; a RabbitMQ provider is present and selected through EventingOptions.Provider. Provider selection alone does not provision a broker or prove a deployment is configured for it.
Publish with the business transaction
Module code should normally use IOutboxWriter.AddAsync for durable integration delivery. The store persists the serialized event, event identifier, tenant, correlation identifier and dispatch state. It joins an existing compatible ambient database transaction when one is present.
This guarantee depends on the transaction boundary. Writing a business row, committing it, and then separately writing an outbox row leaves a gap if the process fails between them. Create the transaction around both writes using the existing persistence infrastructure, and test a forced rollback. Direct IEventBus publication does not provide durable recording with the business commit.
Make consumers tolerate repeat delivery
Outbox delivery is at least once. Events may be retried, so a consumer must not assume it sees each business fact only once. The inbox is enabled by default and supports idempotent handling. External effects still need a stable business identifier or equivalent duplication guard.
The source defaults dispatch to a hosted service every 10 seconds, with batches of 100, five maximum retries and exponential backoff beginning at 30 seconds and capped at one hour. A 300-second claim lease prevents concurrent PostgreSQL dispatchers from owning the same batch. These defaults can be overridden; set a lease long enough for actual batch duration.
Keep the tenant with the message
IIntegrationEvent carries tenant context. Multitenancy replaces the framework's default scope and drain-provider implementations so handlers are created under the event's tenant and dedicated tenant databases are visited. Constructing a tenant-dependent handler before restoring that context can read the wrong database or no tenant at all.
Verify delivery, not just publication
Test commit, rollback, successful consumption, a consumer failure and retry, and two-tenant isolation. Inspect dead-lettered messages rather than silently discarding exhausted retries. A growing outbox can indicate a stopped dispatcher, a consumer exception or a database absent from enumeration.
For ordinary delayed work, compare the background-job path. For shared transactions, review persistence.