PostgreSQL Provider
The PostgreSQL provider offers full relational database support with Npgsql-based query execution, event sourcing integration, inbox/outbox patterns, and Change Data Capture.
Before You Start
- .NET 8.0+ (or .NET 9/10 for latest features)
- A PostgreSQL instance (local or cloud-hosted)
- Familiarity with data access and IDb interface
Installation
dotnet add package Excalibur.Data.Postgres
Dependencies: Excalibur.Data.Abstractions, Npgsql
Quick Start
using Microsoft.Extensions.DependencyInjection;
services.AddPostgresDataExecutors(() => new NpgsqlConnection(connectionString));
Registration Methods
| Method | What It Registers | Key Options |
|---|---|---|
AddPostgresDataExecutors(factory) | Core data executors | Connection factory |
AddPostgresEventStore(opts) | IEventStore | ConnectionString, SchemaName |
AddPostgresSnapshotStore(opts) | ISnapshotStore | ConnectionString |
AddPostgresInboxStore(opts) | IInboxStore | ConnectionString |
AddPostgresProjectionStore<T>(opts) | IProjectionStore<T> | ConnectionString, TableName |
AddPostgresCdc(opts) | CDC processor | ConnectionString, PublicationName, ReplicationSlotName |
Batch Projection Registration
Register multiple projections sharing the same connection:
services.AddPostgresProjections(connectionString, projections =>
{
projections.Add<OrderSummary>();
projections.Add<CustomerProfile>(o => o.TableName = "customer_views");
});
Change Data Capture
services.AddPostgresCdc(options =>
{
options.ConnectionString = connectionString;
options.PublicationName = "my_publication";
options.ReplicationSlotName = "my_slot";
});
Data Request Pattern
public class GetCustomerRequest : DataRequest<Customer?>
{
public GetCustomerRequest(Guid customerId)
{
Command = new CommandDefinition(
"SELECT * FROM customers WHERE id = @Id",
new { Id = customerId });
}
}
See Also
- Data Providers Overview — Architecture and core abstractions
- SQL Server Provider — Microsoft SQL Server alternative
- Event Sourcing — PostgreSQL event store integration