Trellis.EntityFrameworkCore.Inbox
3.0.0-alpha.417
See the version list below for details.
dotnet add package Trellis.EntityFrameworkCore.Inbox --version 3.0.0-alpha.417
NuGet\Install-Package Trellis.EntityFrameworkCore.Inbox -Version 3.0.0-alpha.417
<PackageReference Include="Trellis.EntityFrameworkCore.Inbox" Version="3.0.0-alpha.417" />
<PackageVersion Include="Trellis.EntityFrameworkCore.Inbox" Version="3.0.0-alpha.417" />
<PackageReference Include="Trellis.EntityFrameworkCore.Inbox" />
paket add Trellis.EntityFrameworkCore.Inbox --version 3.0.0-alpha.417
#r "nuget: Trellis.EntityFrameworkCore.Inbox, 3.0.0-alpha.417"
#:package Trellis.EntityFrameworkCore.Inbox@3.0.0-alpha.417
#addin nuget:?package=Trellis.EntityFrameworkCore.Inbox&version=3.0.0-alpha.417&prerelease
#tool nuget:?package=Trellis.EntityFrameworkCore.Inbox&version=3.0.0-alpha.417&prerelease
Trellis.EntityFrameworkCore.Inbox
The transactional inbox for Trellis — the consume-side complement to the transactional outbox. It makes integration-event consumption idempotent: redeliveries of the same message (a broker lock-renewal timeout, a log offset replay, an outbox re-publish) are deduplicated by message id within the consumer's unit of work, so a handler's local side effects commit exactly once.
Installation
dotnet add package Trellis.EntityFrameworkCore.Inbox
Why
Every durable transport delivers at least once, so a consumer will see the same message twice and must not apply it twice. A "have we handled this id?" check is only correct if the check and the work commit atomically — otherwise a crash in between reprocesses or drops. The inbox records that a message was processed in the same transaction as the handler's side effects, so the proof and the work are inseparable.
Quick Example
Two wiring points — the dedup table and the dispatcher — plus a transport adapter you own.
// 1. Map the TrellisInboxMessages dedup table (OnModelCreating).
protected override void OnModelCreating(ModelBuilder modelBuilder) =>
modelBuilder.AddTrellisInbox();
// 2. Register the dispatcher, store, options, and the handlers that consume the events.
services.AddTrellis(trellis => trellis
.UseIntegrationEvents(typeof(Program).Assembly) // your IIntegrationEventHandler<T> consumers
.UseEntityFrameworkUnitOfWork<AppDbContext>()
.UseInbox<AppDbContext>(o => o.ConsumerId = "orders-service"));
// 3. Your transport adapter hands each received message to the inbox.
public sealed class OrdersBrokerConsumer(IInboxDispatcher inbox)
{
public Task OnMessageAsync(TransportMessage raw, CancellationToken ct) =>
inbox.DispatchAsync(new IntegrationEnvelope(raw.MessageId, Deserialize(raw)), ct);
}
The dispatcher deduplicates on (ConsumerId, MessageId) so the event's handlers' side effects commit exactly once, together with the dedup record. A duplicate delivery commits nothing.
Prefer raw DI? Call
services.AddTrellisInbox<AppDbContext>(o => o.ConsumerId = "orders-service")instead of theUseInboxbuilder slot — the table wiring (step 1) is identical.
Key Features
- Atomic dedup — the
(ConsumerId, MessageId)row and the handler side effects commit in oneTContexttransaction. Either both land or neither does. - Effectively-once processing — at-least-once transport delivery becomes exactly-once application of local side effects, per consumer.
- Non-swallowing by design — a handler throw rolls the transaction back and rethrows, so nothing is marked processed and the transport redelivers. (The default integration-event publisher swallows handler errors; the inbox must not.)
- Concurrency-safe — the composite primary key is the guard: when two deliveries race, exactly one inserts the dedup row and the other rolls back as a duplicate.
- Store-agnostic seam —
IInboxStoreis an SPI, so the same idempotency guarantee can be backed by a non-EF store.EfInboxStore<TContext>is the shipped implementation. - Stable dedup key — use the producer's outbox
OutboxMessage.Id(a UUIDv7) carried verbatim by the transport as theMessageId. - Pull-consumer ready —
DispatchAsyncreturnsProcessedvsSkippedDuplicate, andIInboxStore.FilterUnprocessedAsync(consumerId, ids, ct)returns a window's not-yet-processed ids for the gap-free inbox-as-cursor / anti-join model — no fragile high-water cursor. - Resume cursor (optional) —
IConsumerCheckpointStore(AddTrellisConsumerCheckpointStore<TContext>()+AddTrellisConsumerCheckpoints()) durably remembers a pull consumer's position so it resumes instead of rescanning the whole feed. A performance optimization, not a dedup substitute — pair it with an overlap window andFilterUnprocessedAsyncfor correctness.
Delivery & idempotency notes
- The guarantee covers local transactional side effects only — writes through the injected
DbContext. External calls (emails, downstream APIs) happen outside the transaction and still need their own idempotency (an idempotency key, or push them back out through an outbox). ConsumerIdis part of the dedup key. Keep it stable across deploys; renaming it resets dedup history.TrellisInboxMessagesrows can be pruned once they are older than the transport's maximum redelivery window (theProcessedAtcolumn is indexed for this).
Inbox + outbox
The outbox makes a producer's publish reliable (at-least-once); the inbox makes a consumer's receive idempotent (effectively-once). They meet at the message id: the producer's OutboxMessage.Id carried across the wire becomes the inbox MessageId.
Documentation
Part of Trellis
This package is part of the Trellis framework.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net10.0 is compatible. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
-
net10.0
- Mediator.Abstractions (>= 3.0.2)
- Microsoft.EntityFrameworkCore (>= 10.0.9)
- Microsoft.EntityFrameworkCore.Relational (>= 10.0.9)
- Microsoft.Extensions.DependencyInjection (>= 10.0.9)
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 10.0.9)
- Microsoft.Extensions.Logging.Abstractions (>= 10.0.9)
- Microsoft.Extensions.Options (>= 10.0.9)
- OpenTelemetry.Api (>= 1.16.0)
- Trellis.EntityFrameworkCore (>= 3.0.0-alpha.417)
- Trellis.Mediator (>= 3.0.0-alpha.417)
- Trellis.Persistence.Abstractions (>= 3.0.0-alpha.417)
NuGet packages (1)
Showing the top 1 NuGet packages that depend on Trellis.EntityFrameworkCore.Inbox:
| Package | Downloads |
|---|---|
|
Trellis.ServiceDefaults
Opinionated service composition defaults for Trellis web services. Provides a tiered builder that wires ASP integration, Mediator behaviors, FluentValidation, resource authorization, actor providers, and EF Core Unit of Work in canonical order. |
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 3.0.0-alpha.419 | 29 | 6/24/2026 |
| 3.0.0-alpha.418 | 39 | 6/23/2026 |
| 3.0.0-alpha.417 | 46 | 6/23/2026 |