MVFC.Outbox
3.0.0
See the version list below for details.
dotnet add package MVFC.Outbox --version 3.0.0
NuGet\Install-Package MVFC.Outbox -Version 3.0.0
<PackageReference Include="MVFC.Outbox" Version="3.0.0" />
<PackageVersion Include="MVFC.Outbox" Version="3.0.0" />
<PackageReference Include="MVFC.Outbox" />
paket add MVFC.Outbox --version 3.0.0
#r "nuget: MVFC.Outbox, 3.0.0"
#:package MVFC.Outbox@3.0.0
#addin nuget:?package=MVFC.Outbox&version=3.0.0
#tool nuget:?package=MVFC.Outbox&version=3.0.0
MVFC.Outbox
Provides contracts and declarative DI builders to publish saved copies of entities (snapshots), schedule retries, manage messages through backoffice and run the Outbox worker.
Supports .NET 10 and .NET 11.
Built-in stores use the optional IOutboxExecutionStore contract to renew message reservations (leases) automatically and retry saving each result separately, within the configured attempt limit. The worker processes messages in independent slots and runs maintenance separately.
It can confirm completed work during shutdown. Custom stores without this capability keep the previous execution flow. See execution configuration, cancellation limits and mixed-version deployment. The retention rules and native MongoDB TTL stay the same.
ConfirmationRetryAttempts includes the first attempt and limits both result confirmation and recovery from transient renewal failures. There is no retry delay after the final failed attempt.
If FailureClassifier throws, the library logs the classifier error and treats the original execution failure as transient. Lease ownership, attempt limits and cancellation rules still apply.
With renewal disabled, LeaseRenewalInterval is ignored. Fixed-lease timeout and clock margins are still validated. See the complete options reference.
dotnet add package MVFC.Outbox
Namespaces
| Namespace | Main types |
|---|---|
MVFC.Outbox.Aggregates |
AggregateMapping, AggregateRegistry |
MVFC.Outbox.Configuration |
OutboxBuilder, OutboxOptions, OutboxMode |
MVFC.Outbox.Extensions |
AddOutbox, For/ForEach extensions |
MVFC.Outbox.Publishing |
IOutboxPublisher, 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
The examples use the application's services and variables: services, configuration, connection, ct, order and topicId. Register services before building the host. Resolve IOutboxPublisher and your database context/session in the same dependency injection (DI) scope.
using MVFC.Outbox.Extensions;
using MVFC.Outbox.Handlers;
using MVFC.Outbox.MongoDB;
using MVFC.Outbox.MongoDB.Extensions;
using MVFC.Outbox.Publishing;
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: each configuration call returns a new builder. .To(...) and .ToHandler(...) accept params IEnumerable<Guid>:
using MVFC.Outbox.Extensions;
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 (nullrestores the default).WithAttributes(...)copies the supplied dictionary (nullclears custom attributes). Keys must be nonempty, values cannot benull, 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 (default0).
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"
}
}
}
using MVFC.Outbox.Extensions;
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.Extensions;
using MVFC.Outbox.Handlers;
using MVFC.Outbox.MongoDB;
using MVFC.Outbox.MongoDB.Extensions;
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,ProjectIdandAttributes.Handlers must commit their effects before returning and honor
CancellationToken(HandlerTimeoutdefaults to30sand must be shorter thanLeaseDuration).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
Use OutboxAdministration from DI to inspect errors and requeue messages after fixing their cause:
var errors = await administration.GetErrorsAsync(100, ct);
var requeued = await administration.RequeueAsync(messageId, ct);
RequeueAsync accepts Error records that have no active lease. It resets Attempts, IsTerminal, scheduling, queue time and LastErrorCode. It preserves 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 for this publication and a saved JSON copy of custom attributes |
Payload, SchemaVersion |
Saved JSON copy of the entity 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 order and retry scheduling with exponential delay and random variation (jitter) |
LeaseToken, LeaseUntilUtc, Version |
Exclusive reservation and optimistic concurrency |
ProcessedAtUtc, ExpiresAtUtc |
Successful destination completion and processed-record retention |
Timeouts and shutdown
PublishTimeout and HandlerTimeout cancel only the message's token, independently of the worker's stopping token. A message timeout does not stop the worker. Before retrying a cancelled operation, its result must be saved with a valid lease.
During host shutdown, unconfirmed work remains recoverable after the lease expires.
The dispatcher waits for operations that have already started before leaving the processing window. This also applies when shutdown interrupts result confirmation. It stops reserving new messages when the host token is cancelled.
Completion still depends on the host's shutdown deadline and whether the process is forcibly terminated.
Cancellation is cooperative: handlers must pass the received token to their I/O operations. Wolverine's inline sender API cannot cancel a send that has already started, so the library waits for it to finish. Configure suitable timeouts in the transport client.
A timeout does not prove that an external effect failed or was rolled back. Use the stable message ID to make effects idempotent, so repeating a message does not repeat its effect. This is especially necessary when execution can outlast the lease.
Requirements
An 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 and integration tests, use the .NET 11 SDK specified in global.json.
To build the packages, also install .NET 10 targeting support. Keep Docker running. See the playground guide.
Contributing
See CONTRIBUTING.md to set up the environment, run the Cake build and follow the test and coverage conventions. Dependency versions are defined in Directory.Packages.props.
License
Distributed under the Apache License 2.0. See LICENSE for all terms: permissions, redistribution conditions, and limits on warranty and liability.
| 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. net11.0 is compatible. |
-
net10.0
- Microsoft.Extensions.Hosting (>= 10.0.15)
- Microsoft.Extensions.Options.ConfigurationExtensions (>= 10.0.15)
-
net11.0
- Microsoft.Extensions.Hosting (>= 11.0.0)
- Microsoft.Extensions.Options.ConfigurationExtensions (>= 11.0.0)
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.