DKNet.AspCore.Idempotency.NpgsqlStore
10.0.35
dotnet add package DKNet.AspCore.Idempotency.NpgsqlStore --version 10.0.35
NuGet\Install-Package DKNet.AspCore.Idempotency.NpgsqlStore -Version 10.0.35
<PackageReference Include="DKNet.AspCore.Idempotency.NpgsqlStore" Version="10.0.35" />
<PackageVersion Include="DKNet.AspCore.Idempotency.NpgsqlStore" Version="10.0.35" />
<PackageReference Include="DKNet.AspCore.Idempotency.NpgsqlStore" />
paket add DKNet.AspCore.Idempotency.NpgsqlStore --version 10.0.35
#r "nuget: DKNet.AspCore.Idempotency.NpgsqlStore, 10.0.35"
#:package DKNet.AspCore.Idempotency.NpgsqlStore@10.0.35
#addin nuget:?package=DKNet.AspCore.Idempotency.NpgsqlStore&version=10.0.35
#tool nuget:?package=DKNet.AspCore.Idempotency.NpgsqlStore&version=10.0.35
DKNet.AspCore.Idempotency.NpgsqlStore
PostgreSQL persistent storage implementation for DKNet.AspCore.Idempotency.
Overview
This library provides a PostgreSQL-backed storage implementation for idempotency keys, replacing the default distributed-cache storage. It uses Entity Framework Core 10 with the Npgsql provider, and detects concurrent duplicate inserts via Postgres's own unique-violation error code (23505) rather than message inspection.
Installation
dotnet add package DKNet.AspCore.Idempotency.NpgsqlStore
Quick Start
using DKNet.AspCore.Idempotency.NpgsqlStore;
var builder = WebApplication.CreateBuilder(args);
builder.Services.AddIdempotencyWithNpgsqlStore(
builder.Configuration.GetConnectionString("IdempotencyDb")!,
options =>
{
options.Expiration = TimeSpan.FromHours(24);
options.ConflictHandling = IdempotentConflictHandling.CachedResult;
});
var app = builder.Build();
app.MapPost("/orders", CreateOrder).RequiredIdempotentKey();
app.Run();
appsettings.json:
{
"ConnectionStrings": {
"IdempotencyDb": "Host=localhost;Database=MyAppIdempotency;Username=app;Password=changeit"
}
}
Database Schema
A single IdempotencyKeys table, with a unique index (UX_CompositeKey) on CompositeKey that guarantees exactly one stored entry per idempotency key/endpoint/method combination, and a check constraint (CK_StatusCode_Valid) restricting StatusCode to the 100-599 range.
Concurrency Handling
Concurrent requests with the same idempotency key race to insert; the loser's DbUpdateException is inspected for PostgresException.SqlState == PostgresErrorCodes.UniqueViolation ("23505") and swallowed, so only one entry is ever persisted — no application-level locking required.
Requirements
- .NET 10.0+
- PostgreSQL 13+
- DKNet.AspCore.Idempotency (automatically included)
License
MIT License - see LICENSE file for details.
| 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. |
-
net10.0
- DKNet.AspCore.Idempotency (>= 10.0.35)
- Microsoft.EntityFrameworkCore (>= 10.0.10)
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 10.0.10)
- Microsoft.Extensions.Logging.Abstractions (>= 10.0.10)
- Microsoft.Extensions.Options (>= 10.0.10)
- Npgsql.EntityFrameworkCore.PostgreSQL (>= 10.0.3)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.