MVFC.Outbox 1.1.1

There is a newer version of this package available.
See the version list below for details.
dotnet add package MVFC.Outbox --version 1.1.1
                    
NuGet\Install-Package MVFC.Outbox -Version 1.1.1
                    
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="MVFC.Outbox" Version="1.1.1" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="MVFC.Outbox" Version="1.1.1" />
                    
Directory.Packages.props
<PackageReference Include="MVFC.Outbox" />
                    
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 MVFC.Outbox --version 1.1.1
                    
#r "nuget: MVFC.Outbox, 1.1.1"
                    
#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 MVFC.Outbox@1.1.1
                    
#: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=MVFC.Outbox&version=1.1.1
                    
Install as a Cake Addin
#tool nuget:?package=MVFC.Outbox&version=1.1.1
                    
Install as a Cake Tool

MVFC.Outbox

🇧🇷 Leia em Português

CI codecov License Platform NuGet Version NuGet Downloads

Main guide · Playground

Contracts, declarative DI builders, entity snapshot publication, retry scheduling, backoffice administration and the Outbox worker.

Supports .NET 10 and .NET 11.

dotnet add package MVFC.Outbox

Namespaces

Namespace Main types
MVFC.Outbox.Aggregates AggregateMapping, AggregateRegistry
MVFC.Outbox.Configuration OutboxBuilder, OutboxOptions, OutboxMode
MVFC.Outbox.DependencyInjection AddOutbox extension
MVFC.Outbox.Publishing IOutboxPublisher, For/ForEach, OutboxMessageBuilder, OutboxReceipt, OutboxWriteState
MVFC.Outbox.Messages OutboxMessage, OutboxStatus, OutboxDestinationKind
MVFC.Outbox.Handlers IOutboxHandler<T>, OutboxHandlerContext<T>
MVFC.Outbox.Persistence IOutboxStore, IOutboxSchemaInitializer
MVFC.Outbox.Processing OutboxDispatcher, OutboxWorker, OutboxAdministration, RetryDelay
MVFC.Outbox.Transport IOutboxTransport
MVFC.Outbox.Diagnostics Internal generated logging declarations

Configuration and usage

Snippets use application services and variables: services, configuration, connection, ct, order and topicId. Register services before building the host and resolve IOutboxPublisher and your database context/session in the same DI scope.

using MVFC.Outbox.DependencyInjection;
using MVFC.Outbox.Publishing;
using MVFC.Outbox.Handlers;
using MVFC.Outbox.MongoDB;

services.AddOutbox(configuration, outbox => outbox
    .ProducerOnly()
    .MapAggregate<Order, Guid>(order => order.Id, "order")
    .UseMongoDB(mongo =>
    {
        mongo.ConnectionString = connection;
        mongo.DatabaseName = "orders";
    }));

var topicId = Guid.Parse("78214bd7-451a-4896-88be-08d7fcfdc32a");
await publisher.For(order).To(topicId).EnqueueAsync(ct);
await publisher.ForEach(orders).To(topicId).EnqueueAsync(ct);

Combine MVFC.Outbox with a persistence provider (the example above uses MVFC.Outbox.MongoDB). Configure Topics before calling .To(...) and HandlerRoutes before calling .ToHandler(...).

Multiple destinations, project override, and custom attributes

OutboxMessageBuilder is immutable. .To(...) and .ToHandler(...) accept params IEnumerable<Guid>:

var createdTopic = Guid.Parse("78214bd7-451a-4896-88be-08d7fcfdc32a");
var auditedTopic = Guid.Parse("3b914e8e-e144-4f70-a520-e7d30dbe5bca");

await publisher.For(order)
    .To(createdTopic, auditedTopic)
    .WithProjectId("billing-project")
    .WithAttributes(new Dictionary<string, string>
    {
        ["source"] = "checkout",
        ["trace-id"] = "trace-123"
    })
    .WithPriority(1)
    .EnqueueAsync(ct);
  • WithProjectId(string?) overrides the transport's default project for this operation (null restores the default).
  • WithAttributes(...) copies the supplied dictionary (null clears custom attributes). Keys must be nonempty, values cannot be null, and reserved library keys cannot be replaced: outbox-message-id, outbox-topic-id, aggregate-id, aggregate-type, schema-version.
  • WithMessageIds(params Guid[]) supplies explicit IDs (1 per generated message: entities × destinations), nonempty and distinct. When omitted, Guid.NewGuid() is generated per message.
  • WithPriority(int) overrides message priority (default 0).

Topics, routes, and transactional handlers

{
  "Outbox": {
    "Topics": {
      "78214bd7-451a-4896-88be-08d7fcfdc32a": "orders-created",
      "3b914e8e-e144-4f70-a520-e7d30dbe5bca": "orders-audited"
    },
    "HandlerRoutes": {
      "a6d21ecc-9cd9-4486-8174-e7f3cae7acb8": "order"
    }
  }
}
var routeId = Guid.Parse("a6d21ecc-9cd9-4486-8174-e7f3cae7acb8");
await publisher.For(order).ToHandler(routeId).EnqueueAsync(ct);

Register Handle<TMessage, THandler>() after MapAggregate in the consumer/worker process:

using MVFC.Outbox.DependencyInjection;
using MVFC.Outbox.Handlers;
using MVFC.Outbox.MongoDB;

services.AddOutbox(configuration, outbox => outbox.ConsumerProducer()
    .MapAggregate<Order, Guid>(order => order.Id, "order")
    .UseMongoDB(mongo =>
    {
        mongo.ConnectionString = connection;
        mongo.DatabaseName = "orders";
    })
    .Handle<Order, ProcessOrderHandler>());

public sealed class ProcessOrderHandler : IOutboxHandler<Order>
{
    public ValueTask HandleAsync(OutboxHandlerContext<Order> context, CancellationToken ct)
    {
        Console.WriteLine($"Handling {context.Message.Id}, message {context.MessageId}, attempt {context.Attempt}");
        return ValueTask.CompletedTask;
    }
}

public sealed record Order(Guid Id, decimal Total);
  • Each handler execution runs in its own DI scope and receives Message, MessageId, RouteId, AggregateId, AggregateType, Attempt, ProjectId and Attributes.
  • Handlers must commit their effects before returning and honor CancellationToken (HandlerTimeout defaults to 30s and must be shorter than LeaseDuration).
  • Delivery is at least once; persistent side effects require idempotency by context.MessageId. See the complete transaction-idempotent example.
  • Missing routes or handlers result in terminal errors (IsTerminal = true), never Pub/Sub fallback.

Backoffice administration

Resolve OutboxAdministration to inspect error records and requeue messages after fixing the root cause:

var errors = await administration.GetErrorsAsync(100, ct);
var requeued = await administration.RequeueAsync(messageId, ct);

RequeueAsync accepts Error records without an active lease and resets Attempts, IsTerminal, scheduling, queue time and LastErrorCode while preserving identity, payload, destination kind, topic/route and priority.

Message record fields

Field group Purpose
Id, TopicId Stable message ID and logical destination GUID
AggregateId, AggregateType, MessageType Entity identity and stable alias, independent of CLR assembly names
DestinationKind Transport = 0 or Handler = 1; persists the choice without fallback
ProjectId, AttributesJson Optional project override and custom attributes JSON snapshot
Payload, SchemaVersion JSON snapshot and envelope schema version (currently 1)
Status, Attempts, IsTerminal, LastErrorCode Numeric lifecycle (Pending = 0, Error = 1, Processed = 2), failure count and sanitized error classification
Priority, CreatedAtUtc, QueuedAtUtc, NextAttemptAtUtc Selection and exponential jitter retry scheduling
LeaseToken, LeaseUntilUtc, Version Exclusive reservation and optimistic concurrency
ProcessedAtUtc, ExpiresAtUtc Successful destination completion and processed-record retention

Timeouts and shutdown

PublishTimeout and HandlerTimeout cancel the per-message token, independently of the worker's stopping token. An individual timeout does not stop the worker. A cancelled operation can be retried only after its outcome is recorded with a valid lease; host shutdown leaves unconfirmed work recoverable after lease expiration.

The dispatcher awaits all operations already started before leaving the processing window, including when shutdown interrupts result confirmation. New reservations stop when the host token is cancelled. The host's shutdown budget and forced process termination remain external limits on graceful completion.

Cancellation is cooperative: handlers must pass the supplied token to their I/O operations. Wolverine's inline sender API does not expose cancellation for an already-started send, so the library awaits its actual completion; configure appropriate timeouts in the underlying client. A timeout does not prove that an external effect failed or was rolled back. Keep effects idempotent using the stable message ID, especially when execution can exceed the lease.

Requirements

  • A consumer application targeting .NET 10 or .NET 11.
  • A .NET host with dependency injection and a persistence provider. Configure a transport for topic publication or register typed handlers for local processing.
  • For development, the playground or integration tests: the .NET 11 SDK selected by global.json, .NET 10 targeting support to build the packages, and Docker running. See the playground guide.

Contributing

See CONTRIBUTING.md to prepare the environment, run the Cake build and follow the testing and coverage conventions. Dependency versions are centralized in Directory.Packages.props.

License

Distributed under the Apache License 2.0. See LICENSE for the complete terms, including permissions, redistribution conditions, and warranty and liability limitations.

Product 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.  net11.0 is compatible. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (3)

Showing the top 3 NuGet packages that depend on MVFC.Outbox:

Package Downloads
MVFC.Outbox.EntityFrameworkCore

Shared EF Core model, transactional staging, conditional relational updates and versioned Outbox persistence.

MVFC.Outbox.Wolverine

Confirmed Outbox publication through Wolverine's public inline transport senders.

MVFC.Outbox.MongoDB

Native MongoDB Driver Outbox provider with transactional batches, atomic leases and TTL indexes.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
6.0.0 0 12/4/2026
5.0.0 70 12/3/2026
4.1.0 77 12/2/2026
4.0.0 108 12/1/2026
3.0.0 116 12/1/2026
2.0.1 155 11/30/2026
2.0.0 159 11/30/2026
1.1.1 167 11/30/2026
1.1.0 179 11/30/2026
1.0.1 163 11/30/2026
1.0.0 165 11/30/2026