MVFC.Outbox.PostgreSql
1.0.1
See the version list below for details.
dotnet add package MVFC.Outbox.PostgreSql --version 1.0.1
NuGet\Install-Package MVFC.Outbox.PostgreSql -Version 1.0.1
<PackageReference Include="MVFC.Outbox.PostgreSql" Version="1.0.1" />
<PackageVersion Include="MVFC.Outbox.PostgreSql" Version="1.0.1" />
<PackageReference Include="MVFC.Outbox.PostgreSql" />
paket add MVFC.Outbox.PostgreSql --version 1.0.1
#r "nuget: MVFC.Outbox.PostgreSql, 1.0.1"
#:package MVFC.Outbox.PostgreSql@1.0.1
#addin nuget:?package=MVFC.Outbox.PostgreSql&version=1.0.1
#tool nuget:?package=MVFC.Outbox.PostgreSql&version=1.0.1
MVFC.Outbox.PostgreSql
PostgreSQL Outbox provider using EF Core and Npgsql.
Supports .NET 10 and .NET 11.
dotnet add package MVFC.Outbox.PostgreSql
Configuration and usage
Snippets use application services and variables: services, configuration, connection, ct, order and topicId. Register your DbContext with UseNpgsql, map model.AddOutbox() in OnModelCreating, and resolve IOutboxPublisher and ApplicationDbContext in the same DI scope.
using Microsoft.Extensions.DependencyInjection;
using Microsoft.EntityFrameworkCore;
using MVFC.Outbox.DependencyInjection;
using MVFC.Outbox.EntityFrameworkCore;
using MVFC.Outbox.Publishing;
using MVFC.Outbox.PostgreSql;
services.AddDbContext<ApplicationDbContext>(db => db.UseNpgsql(connection));
services.AddOutbox(configuration, outbox => outbox.ProducerOnly()
.MapAggregate<Order, Guid>(order => order.Id, "order")
.UsePostgreSql<ApplicationDbContext>(connection));
// 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 publisher.ForEach(otherOrders).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.AddOutbox().ToTable("outbox");
}
}
public sealed record Order(Guid Id, decimal Total);
- Generic vs non-generic overload:
UsePostgreSql<ApplicationDbContext>(connection)shares your application'sDbContextand transaction (EnqueueAsyncreturnsStagedand persists onSaveChangesAsync/commit). The non-genericUsePostgreSql(connection)uses an isolated Outbox-only context and does not automatically join another context's transaction. - Retention: processed records are deleted by the
ConsumerProducerworker in bounded batches (CleanupInterval,CleanupBatchSize), supported by the expiration index.
Schema initialization and existing databases
The database must already exist. When AddOutbox(...UsePostgreSql...) is registered, resolve IOutboxSchemaInitializer directly. For a dedicated deployment step without topics or a worker, use AddPostgreSqlOutboxSchema:
using MVFC.Outbox.PostgreSql;
using MVFC.Outbox.Persistence;
services.AddPostgreSqlOutboxSchema(connection);
await using var scope = provider.CreateAsyncScope();
await scope.ServiceProvider.GetRequiredService<IOutboxSchemaInitializer>().InitializeAsync(ct);
InitializeAsyncis idempotent, creates theoutboxtable if missing, and repairs missing indexes (ix_outbox_dispatch,ix_outbox_aggregate,ix_outbox_lease,ix_outbox_expiration) without modifying unrelated tables. Run it once per deployment step using a DDL-capable identity.- Existing databases:
InitializeAsyncdoes not add columns to an existing table. Before deploying versions withDestinationKind(Transport = 0,Handler = 1),ProjectIdandAttributesJson, apply a reviewed EF migration or equivalent DDL on your Outbox table:
ALTER TABLE outbox ADD COLUMN "DestinationKind" integer NOT NULL DEFAULT 0;
ALTER TABLE outbox ADD COLUMN "ProjectId" varchar(256) NULL;
ALTER TABLE outbox ADD COLUMN "AttributesJson" text NULL;
Requirements
- A consumer application targeting .NET 10 or .NET 11.
- Access to a PostgreSQL database and an EF Core context configured with Npgsql. Schema initialization needs permission to create the Outbox table and indexes; existing tables require the migrations described above.
- 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)
- MVFC.Outbox.EntityFrameworkCore (>= 1.0.1)
- Npgsql.EntityFrameworkCore.PostgreSQL (>= 10.0.4)
-
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.EntityFrameworkCore (>= 1.0.1)
- Npgsql.EntityFrameworkCore.PostgreSQL (>= 10.0.4)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.