MVFC.Outbox.MongoDB.EntityFrameworkCore
1.1.0
See the version list below for details.
dotnet add package MVFC.Outbox.MongoDB.EntityFrameworkCore --version 1.1.0
NuGet\Install-Package MVFC.Outbox.MongoDB.EntityFrameworkCore -Version 1.1.0
<PackageReference Include="MVFC.Outbox.MongoDB.EntityFrameworkCore" Version="1.1.0" />
<PackageVersion Include="MVFC.Outbox.MongoDB.EntityFrameworkCore" Version="1.1.0" />
<PackageReference Include="MVFC.Outbox.MongoDB.EntityFrameworkCore" />
paket add MVFC.Outbox.MongoDB.EntityFrameworkCore --version 1.1.0
#r "nuget: MVFC.Outbox.MongoDB.EntityFrameworkCore, 1.1.0"
#:package MVFC.Outbox.MongoDB.EntityFrameworkCore@1.1.0
#addin nuget:?package=MVFC.Outbox.MongoDB.EntityFrameworkCore&version=1.1.0
#tool nuget:?package=MVFC.Outbox.MongoDB.EntityFrameworkCore&version=1.1.0
MVFC.Outbox.MongoDB.EntityFrameworkCore
MongoDB Outbox CRUD through EF Core, using the native MongoDB driver for schema and index provisioning.
Supports .NET 10 and .NET 11. Both framework targets share EF Core 10 to match the MongoDB EF Core provider line.
dotnet add package MVFC.Outbox.MongoDB.EntityFrameworkCore
Configuration and usage
Snippets use application services and variables: services, configuration, connection, ct, order and topicId. Register your DbContext with UseMongoDB, map model.AddOutbox().ToCollection("outbox") in OnModelCreating, and align ConnectionString, DatabaseName and CollectionName between UseMongoDB and UseMongoDBEntityFramework.
using Microsoft.Extensions.DependencyInjection;
using Microsoft.EntityFrameworkCore;
using MongoDB.EntityFrameworkCore.Extensions;
using MongoDB.EntityFrameworkCore.Metadata;
using MVFC.Outbox.DependencyInjection;
using MVFC.Outbox.EntityFrameworkCore;
using MVFC.Outbox.MongoDB.EntityFrameworkCore;
using MVFC.Outbox.Publishing;
services.AddDbContext<ApplicationDbContext>(db => db.UseMongoDB(connection, "orders"));
services.AddOutbox(configuration, outbox => outbox.ProducerOnly()
.MapAggregate<Order, Guid>(order => order.Id, "order")
.UseMongoDBEntityFramework<ApplicationDbContext>(mongo =>
{
mongo.ConnectionString = connection;
mongo.DatabaseName = "orders";
mongo.CollectionName = "outbox";
}));
// Same scoped ApplicationDbContext used by the publisher:
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);
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.Entity<Order>().ToCollection("orders");
model.AddOutbox().ToCollection("outbox");
}
}
public sealed record Order(Guid Id, decimal Total);
- Runtime & transactions: CRUD uses the shared EF Core adapter (with
Versionoptimistic concurrency);EnqueueAsyncreturnsStagedand requiresSaveChangesAsync/commit. MongoDB transactions require a replica set or sharded cluster. - Non-generic overload:
UseMongoDBEntityFramework(mongo => ...)creates a separate Outbox-onlyDbContextand does not share transactions with another business context.
Dedicated index initialization and existing collections
When AddOutbox(...UseMongoDBEntityFramework...) is registered, resolve IOutboxSchemaInitializer directly. For a dedicated initialization step without topics or a worker, use AddMongoDBEntityFrameworkOutboxSchema:
using MVFC.Outbox.MongoDB.EntityFrameworkCore;
using MVFC.Outbox.Persistence;
services.AddMongoDBEntityFrameworkOutboxSchema(mongo =>
{
mongo.ConnectionString = connection;
mongo.DatabaseName = "orders";
mongo.CollectionName = "outbox";
});
await using var scope = provider.CreateAsyncScope();
await scope.ServiceProvider.GetRequiredService<IOutboxSchemaInitializer>().InitializeAsync(ct);
InitializeAsyncuses the native MongoDB driver to create the Outbox collection and indexes (including the TTL index onExpiresAtUtcwithexpireAfterSeconds: 0); manage business collections separately.- Documents without
ProjectIdorAttributesJsonremain readable. For documents created beforeDestinationKind(Transport = 0,Handler = 1), backfill before deployment:
db.outbox.updateMany(
{ DestinationKind: { $exists: false } },
{ $set: { DestinationKind: 0 } }
);
Requirements
- A consumer application targeting .NET 10 or .NET 11.
- A MongoDB EF Core DbContext with the Outbox mapping. Transactional publication requires MongoDB configured as a replica set or sharded cluster.
- 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.EntityFrameworkCore (>= 10.0.15)
- Microsoft.EntityFrameworkCore.Relational (>= 10.0.15)
- Microsoft.Extensions.Hosting (>= 10.0.15)
- Microsoft.Extensions.Options.ConfigurationExtensions (>= 10.0.15)
- MongoDB.Driver (>= 3.14.1)
- MongoDB.EntityFrameworkCore (>= 10.0.6)
- MVFC.Outbox.EntityFrameworkCore (>= 1.1.0)
- MVFC.Outbox.MongoDB (>= 1.1.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)
- MongoDB.Driver (>= 3.14.1)
- MongoDB.EntityFrameworkCore (>= 10.0.6)
- MVFC.Outbox.EntityFrameworkCore (>= 1.1.0)
- MVFC.Outbox.MongoDB (>= 1.1.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.