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 — Outbox

L3StableNuGet: v3.0.0Local HEAD: v4.2.0AOT: Partial

Verified patterns for transactional message staging and fault-tolerant broker publishing on .NET 10.

Wrap your active DbTransaction with ToOutboxContext() (or new DbTransactionContext(tx)) before calling CommitAsync():

  1. Begin an ADO.NET DbTransaction (await using var tx = await connection.BeginTransactionAsync(ct);).
  2. Execute domain INSERT/UPDATE statements inside tx.
  3. Stage the [OutboxMessage] event via IOutbox bound to tx.ToOutboxContext(), then commit tx so both domain state and outbox row commit atomically.
using System;
using System.Net.Sockets;
using System.Threading.Tasks;
using EricksonLopez.Outbox;
namespace Example.OutboxQuickStart;
public sealed class SafeBrokerPublisher : IBrokerPublisher
{
public string BrokerSystemName => "rabbitmq";
public ValueTask<DispatchResult> PublishRawAsync(
OutboxMessage message,
OutboxMessageMetadata metadata,
DispatchContext context)
{
try
{
// Dispatch message.Payload to the broker transport here.
return ValueTask.FromResult(DispatchResult.Ok());
}
catch (SocketException ex)
{
return ValueTask.FromResult(DispatchResult.FailAndRetry(ex));
}
catch (Exception ex)
{
return ValueTask.FromResult(DispatchResult.FailFatal(ex));
}
}
}