MVFC.Outbox
1.0.1
See the version list below for details.
dotnet add package MVFC.Outbox --version 1.0.1
NuGet\Install-Package MVFC.Outbox -Version 1.0.1
<PackageReference Include="MVFC.Outbox" Version="1.0.1" />
<PackageVersion Include="MVFC.Outbox" Version="1.0.1" />
<PackageReference Include="MVFC.Outbox" />
paket add MVFC.Outbox --version 1.0.1
#r "nuget: MVFC.Outbox, 1.0.1"
#:package MVFC.Outbox@1.0.1
#addin nuget:?package=MVFC.Outbox&version=1.0.1
#tool nuget:?package=MVFC.Outbox&version=1.0.1
MVFC.Outbox
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 (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"
}
}
}
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,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
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 |
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 | 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.