ZeroAlloc.Outbox.Generator 2.0.0

There is a newer version of this package available.
See the version list below for details.
dotnet add package ZeroAlloc.Outbox.Generator --version 2.0.0
                    
NuGet\Install-Package ZeroAlloc.Outbox.Generator -Version 2.0.0
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="ZeroAlloc.Outbox.Generator" Version="2.0.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="ZeroAlloc.Outbox.Generator" Version="2.0.0" />
                    
Directory.Packages.props
<PackageReference Include="ZeroAlloc.Outbox.Generator" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add ZeroAlloc.Outbox.Generator --version 2.0.0
                    
#r "nuget: ZeroAlloc.Outbox.Generator, 2.0.0"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package ZeroAlloc.Outbox.Generator@2.0.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=ZeroAlloc.Outbox.Generator&version=2.0.0
                    
Install as a Cake Addin
#tool nuget:?package=ZeroAlloc.Outbox.Generator&version=2.0.0
                    
Install as a Cake Tool

ZeroAlloc.Outbox

Source-generated transactional outbox for .NET. Annotate a message type with [OutboxMessage] and a Roslyn source generator emits a typed writer and dispatcher bridge — no reflection, no boxing, AOT-safe. Backed by EF Core (production) or in-memory (tests), with a built-in polling worker, exponential-backoff retry, and dead-letter support.

NuGet NuGet NuGet NuGet Build License: MIT


Install

# Core abstractions + source generator (always required)
dotnet add package ZeroAlloc.Outbox
dotnet add package ZeroAlloc.Outbox.Generator

# Pick a store:
dotnet add package ZeroAlloc.Outbox.EfCore    # production — Entity Framework Core
dotnet add package ZeroAlloc.Outbox.InMemory  # testing — in-process, no database

Quick start

1. Annotate your message:

using ZeroAlloc.Outbox;

[OutboxMessage]
public sealed record OrderPlaced(int OrderId, decimal Amount);

The generator emits IOutboxWriter<OrderPlaced> and its DI registration extension.

2. Register with DI:

builder.Services.AddOutbox(options =>
        {
            options.PollingInterval = TimeSpan.FromSeconds(5);
            options.BatchSize       = 50;
            options.MaxAttempts     = 3;
        })
        .WithEfCore<AppDbContext>()      // or .WithInMemoryStore()
        .AddOrderPlacedOutbox();         // generated extension

3. Write in a transaction:

public class OrderService(IOutboxWriter<OrderPlaced> writer, AppDbContext db)
{
    public async Task PlaceOrderAsync(Order order, CancellationToken ct)
    {
        db.Orders.Add(order);
        await db.SaveChangesAsync(ct);
        await writer.WriteAsync(new OrderPlaced(order.Id, order.Total), ct: ct);
    }
}

For atomic writes (both or neither commit), pass the DbTransaction explicitly. See EF Core Transaction.

4. Implement a dispatcher:

public class OrderPlacedDispatcher(IMessageBus bus) : IOutboxDispatcher<OrderPlaced>
{
    public async Task DispatchAsync(OrderPlaced message, CancellationToken ct)
        => await bus.PublishAsync(message, ct);
}

// Register the dispatcher
builder.Services.AddTransient<IOutboxDispatcher<OrderPlaced>, OrderPlacedDispatcher>();

Dashboard

Operate the outbox at runtime: inspect pending / retry / dead-lettered / dispatched messages, watch a live throughput chart, and requeue or cancel individual messages.

Add the package, then register the event publisher and map the endpoints:

dotnet add package ZeroAlloc.Outbox.Dashboard
// Register the publisher (required for SSE live updates)
builder.Services.AddOutbox().WithDashboardEvents();

// Map the dashboard endpoints
app.MapOutboxDashboard("/outbox");

// Optional: protect with auth
app.MapOutboxDashboard("/outbox").RequireAuthorization("AdminPolicy");

The mapped root (/outbox) serves the HTML dashboard; REST endpoints (snapshot, throughput, requeue, cancel, force-dispatch) and the SSE stream (events) live under the same prefix.

Security

The dashboard exposes write actions (requeue, cancel, force-dispatch) as POST endpoints:

  • POST /outbox/api/messages/{id}/requeue
  • POST /outbox/api/messages/{id}/cancel
  • POST /outbox/api/messages/{id}/force-dispatch

Never mount the dashboard unauthenticated in a production environment. Always apply authentication/authorization:

app.MapOutboxDashboard("/outbox").RequireAuthorization("AdminPolicy");

The IEndpointConventionBuilder returned by MapOutboxDashboard supports all standard ASP.NET Core auth middleware (RequireAuthorization, AllowAnonymous, route filters, etc.).

CSRF protection is the host application's responsibility — the dashboard does not emit or validate anti-forgery tokens. If your authentication scheme is cookie-based, apply the standard ASP.NET Core [ValidateAntiForgeryToken] or enable the antiforgery middleware as appropriate.

What the dashboard shows

  • Pending — messages awaiting their first dispatch attempt
  • Retry queue — messages that have failed at least once and are scheduled for retry
  • Dead-lettered — messages that exceeded MaxAttempts, with the last failure reason
  • Dispatched — most-recently succeeded messages
  • Throughput — SVG chart of dispatched + failed counts per minute
  • ActionsRequeue a dead-lettered message · Cancel a pending one · Force dispatch to run it now
Tab Screenshot
Pending — queue of messages awaiting first dispatch Pending tab
Retry — failed messages with back-off schedule Retry tab
Dead-lettered — exhausted retries with last error Dead-lettered tab
Dispatched — recently-succeeded history feeding the throughput chart Dispatched tab

The dashboard is fully responsive — tablet (768 × 1024) and mobile (375 × 812) captures live in docs/screenshots/.

Blazor component

For apps already using Blazor, ZeroAlloc.Outbox.Dashboard.Blazor ships an <OutboxDashboard /> component that embeds the dashboard via iframe:

dotnet add package ZeroAlloc.Outbox.Dashboard.Blazor
@* In any Razor page / component *@
<OutboxDashboard BaseUrl="/outbox" />

You still need MapOutboxDashboard("/outbox") — the Blazor component is a thin wrapper around the mapped endpoints.


Features

Feature Notes
Source-generated writers [OutboxMessage] triggers generator; typed IOutboxWriter<T> emitted at compile time
Typed dispatchers IOutboxDispatcher<T> — implement once, wire to any transport (bus, HTTP, email)
EF Core store Writes and reads via DbContext; enlist in ambient transaction for atomicity
InMemory store Thread-safe in-process store for unit and integration tests
Polling worker OutboxWorkerService (IHostedService) polls on configurable interval with scope isolation
Exponential backoff Retry delay = RetryBaseDelay × 2^(attempt-1); configurable via OutboxOptions
Dead-letter Entries that exceed MaxAttempts are dead-lettered with the failure reason
AOT / trimmer safe All dispatch code is generated; no Type.GetType, no MakeGenericType
IOptions<OutboxOptions> Full options support with hot-reload via standard Microsoft.Extensions.Options

Diagnostics

ID Severity Description
ZO0001 Warning [OutboxMessage] applied to an interface — code will not be generated
ZO0002 Warning [OutboxMessage] applied to a static class — code will not be generated
ZO0003 Warning [OutboxMessage] applied to a nested type — use a top-level type for a stable type discriminator

Documentation

Full docs live in docs/:


License

MIT

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  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. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • .NETStandard 2.0

    • No dependencies.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
2.5.0 20 5/14/2026
2.4.1 47 5/12/2026
2.4.0 85 5/4/2026
2.3.1 87 5/3/2026
2.3.0 85 5/1/2026
2.2.1 103 4/28/2026
2.2.0 90 4/28/2026
2.1.1 90 4/28/2026
2.1.0 96 4/26/2026
2.0.0 90 4/25/2026
1.3.0 87 4/25/2026
1.2.2 101 4/25/2026
1.2.1 88 4/24/2026
1.2.0 89 4/24/2026
1.1.2 101 4/23/2026
1.1.1 101 4/23/2026
1.1.0 95 4/22/2026
1.0.1 89 4/22/2026
1.0.0 101 4/20/2026
0.1.0 92 4/20/2026