MVFC.Outbox.EntityFrameworkCore
6.0.0
dotnet add package MVFC.Outbox.EntityFrameworkCore --version 6.0.0
NuGet\Install-Package MVFC.Outbox.EntityFrameworkCore -Version 6.0.0
<PackageReference Include="MVFC.Outbox.EntityFrameworkCore" Version="6.0.0" />
<PackageVersion Include="MVFC.Outbox.EntityFrameworkCore" Version="6.0.0" />
<PackageReference Include="MVFC.Outbox.EntityFrameworkCore" />
paket add MVFC.Outbox.EntityFrameworkCore --version 6.0.0
#r "nuget: MVFC.Outbox.EntityFrameworkCore, 6.0.0"
#:package MVFC.Outbox.EntityFrameworkCore@6.0.0
#addin nuget:?package=MVFC.Outbox.EntityFrameworkCore&version=6.0.0
#tool nuget:?package=MVFC.Outbox.EntityFrameworkCore&version=6.0.0
MVFC.Outbox.EntityFrameworkCore
Provides the shared EF Core model, transactional staging and conditional relational updates for the Outbox. Also provides a versioned adapter for custom persistence registrations.
Supports .NET 10 and .NET 11. Both targets use EF Core 10 for compatibility with the MongoDB EF Core provider.
dotnet add package MVFC.Outbox.EntityFrameworkCore
ProducerOnly saves messages; ConsumerProducer also starts the worker. Manual dispatch uses the same confirmation flow (IOutboxExecutionPersistence). For custom registration updates, see the 4.0.0 migration guide.
Configuration and usage
These example variables come from your application: services, configuration, connection, ct, order and topicId. Register your DbContext once and map AddOutboxTable() in OnModelCreating.
AddOutboxTable() maps the outbox table for PostgreSQL/MySQL. MongoDB EF Core provides AddOutboxCollection() for the outbox collection. Both accept a custom name; AddOutboxTable() also accepts schema. The original AddOutbox() remains available for manual mapping.
Resolve IOutboxPublisher and your DbContext in the same dependency injection (DI) scope.
using MVFC.Outbox.EntityFrameworkCore;
using MVFC.Outbox.EntityFrameworkCore.Extensions;
using MVFC.Outbox.Extensions;
using MVFC.Outbox.Publishing;
using Microsoft.EntityFrameworkCore;
public sealed class ApplicationDbContext(DbContextOptions<ApplicationDbContext> options)
: DbContext(options)
{
public DbSet<Order> Orders => Set<Order>();
protected override void OnModelCreating(ModelBuilder model)
{
model.Entity<Order>().HasKey(order => order.Id);
model.AddOutboxTable();
}
}
public sealed record Order(Guid Id, decimal Total);
public sealed class OrderService(ApplicationDbContext database, IOutboxPublisher publisher)
{
public async Task CreateAsync(Order order, Guid topicId, CancellationToken ct)
{
await using var transaction = await database.Database.BeginTransactionAsync(ct);
database.Orders.Add(order);
await publisher.For(order).To(topicId).EnqueueAsync(ct);
await database.SaveChangesAsync(ct);
await transaction.CommitAsync(ct);
}
}
Supported EF Core providers
This package provides the shared storage layer. Choose a database provider to register IOutboxPersistence and IOutboxSchemaInitializer:
| Provider package | Context configuration | Outbox builder | Model mapping |
|---|---|---|---|
MVFC.Outbox.PostgreSql |
UseNpgsql(connection) |
UsePostgreSql<TContext>(connection) |
model.AddOutboxTable() |
MVFC.Outbox.MySql |
UseMySQL(connection) |
UseMySql<TContext>(connection) |
model.AddOutboxTable() |
MVFC.Outbox.MongoDB.EntityFrameworkCore |
UseMongoDB(connection, db) |
UseMongoDBEntityFramework<TContext>(...) |
model.AddOutboxCollection() |
Transaction boundaries and concurrency
Atomic business writes: provider overloads with your context type (
Use*<TContext>) prepareOutboxMessageentities in the registeredDbContext.EnqueueAsyncreturnsOutboxWriteState.Staged.Call
SaveChangesAsyncand commit the transaction to save the business data and messages together.Without a context type: registering without
<TContext>uses a separate Outbox-onlyDbContext. It cannot save business writes from another context in the same atomic operation.Relay isolation: worker operations (
ClaimAsync,CompleteAsync,FailAsync) run in separate DI scopes. Built-in relational providers reserve withSKIP LOCKEDand update state conditionally by token and lease validity. The generic EF adapter detects conflicting tracked updates throughVersion. Every successful transition increments the version.State updates within each context remain sequential.
Existing databases:
IOutboxSchemaInitializercreates missing Outbox structures and indexes. It does not change other tables or add columns (DestinationKind,ProjectId,Attributes) to existing tables. Use EF Core migrations to update existing databases.Use
EnsureCreatedonly for local demos.
Relational worker operations
| Implementation | Use |
|---|---|
RelationalOutboxPersistence<TContext> |
Shares conditional PostgreSQL and MySQL updates without entity tracking. Each provider reserves messages with its own atomic operations. |
EntityFrameworkOutboxPersistence<TContext> |
Adapter with tracked, versioned saves, available for custom registrations and custom MongoDB mappings. |
Built-in providers select automatically. Global filters or custom converters retain versioned EF acquisition in the worker's scope. Publication still uses the application's context; all providers share one dispatcher and confirmation flow.
Before starting workers, apply schema initialization or migrations to include ix_outbox_ready and ix_outbox_retry. They support the two orderings by status, priority, age and ID. Existing indexes remain in place.
The 6.0.0 model uses EventType, Attributes, RetryCount, Error and the new nullable ClaimedAtUtc field. Update custom migrations and mappings before upgrading. See the field migration; initialization does not alter existing columns.
Requirements
An application targeting .NET 10 or .NET 11.
An EF Core DbContext with the Outbox model mapping and a compatible database provider. Commit business changes and Outbox records through the same context and transaction.
For development, use the .NET 11 SDK in global.json and .NET 10 targeting support. The playground and integration tests also require Docker. See the playground guide.
Contributing
See CONTRIBUTING.md for setup, Cake builds, tests and coverage conventions. Dependencies are listed 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.EntityFrameworkCore (>= 10.0.15)
- Microsoft.EntityFrameworkCore.Relational (>= 10.0.15)
- Microsoft.Extensions.Hosting (>= 10.0.15)
- Microsoft.Extensions.Options.ConfigurationExtensions (>= 10.0.15)
- MVFC.Outbox (>= 6.0.0)
-
net11.0
- Microsoft.EntityFrameworkCore (>= 10.0.15)
- Microsoft.EntityFrameworkCore.Relational (>= 10.0.15)
- Microsoft.Extensions.Hosting (>= 11.0.0)
- Microsoft.Extensions.Options.ConfigurationExtensions (>= 11.0.0)
- MVFC.Outbox (>= 6.0.0)
NuGet packages (3)
Showing the top 3 NuGet packages that depend on MVFC.Outbox.EntityFrameworkCore:
| Package | Downloads |
|---|---|
|
MVFC.Outbox.MySql
MySQL Outbox provider using Oracle's MySQL EF Core integration. |
|
|
MVFC.Outbox.PostgreSql
PostgreSQL Outbox provider using EF Core and Npgsql. |
|
|
MVFC.Outbox.MongoDB.EntityFrameworkCore
Transactional Outbox staging through EF Core, with native MongoDB worker operations and schema provisioning. |
GitHub repositories
This package is not used by any popular GitHub repositories.