Skip to content

Latest commit

 

History

History
62 lines (42 loc) · 2.82 KB

index.md

File metadata and controls

62 lines (42 loc) · 2.82 KB

DKNet.AspCore.Idempotency.MsSqlStore

A SQL Server ledger for .NET developers using DKNet minimal-API idempotency.

✨ Why use it?

  • Share reservations across hosts using the same SQL Server database.
  • Keep completed response data in a queryable table.
  • Use the provider’s migrations and structured duplicate-key classification.

🚀 Quick Start

Use a .NET 10 ASP.NET Core project.

dotnet new web -f net10.0 -n PackageDemo
cd PackageDemo
dotnet add package DKNet.AspCore.Idempotency.MsSqlStore

Replace Program.cs with the example, then run dotnet run.

Set ConnectionStrings__Idempotency to a reachable SQL Server database connection string. The account must be able to apply the packaged migrations.

using DKNet.AspCore.Idempotency;
using DKNet.AspCore.Idempotency.MsSqlStore;
var builder = WebApplication.CreateBuilder(args);
var connection = builder.Configuration.GetConnectionString("Idempotency")
    ?? throw new InvalidOperationException("Set ConnectionStrings__Idempotency.");
builder.Services.AddIdempotencyWithMsSqlStore(connection);
var app = builder.Build();
app.MapPost("/orders", () => Results.Ok(new { Accepted = true }))
    .RequiredIdempotentKey();
await app.RunAsync();

POST twice with X-Idempotency-Key: order-1. The first returns 200 and the retry 409. The ledger is shared by hosts using this database.

🏗️ Architecture

The host selects the SQL Server store, whose context factory serves ledger operations and startup migrations.

The provider registers a singleton store and factory, with fresh contexts per operation. The database is supplied by the application operator; startup applies this provider’s migrations.

🔄 How it works

The host registers the SQL provider, applies pending migrations, then validates and reserves each protected request before running and retaining its result.

A live collision is a duplicate; an expired collision can be reclaimed by a conditional update. The core filter decides whether a result is cacheable. Expired rows are not automatically purged.

🧩 Features

🔗 Related packages

  • Idempotency — configure filters, keys and duplicate responses.
  • Relational — inspect shared schema and concurrency.
  • NpgsqlStore — use the other SQL provider.
  • RedisStore — use Redis TTLs instead of SQL rows.