DKNet

Understand schema and migrations

Part of DKNet.AspCore.Idempotency.Relational. The provider’s IdempotencyDbContext inherits the shared context, which discovers mappings in the derived context’s assembly. The provider owns its migrations, SQL column types, and unique-violation classification.

using DKNet.AspCore.Idempotency.MsSqlStore;
using Microsoft.Extensions.DependencyInjection;
var services = new ServiceCollection();
services.AddLogging();
services.AddIdempotencyMsSqlStore("Server=localhost;Database=idempotency;Integrated Security=true;TrustServerCertificate=true");

The provider registers a context factory and startup migration service, and the shared context discovers that provider assembly’s mappings.

This registers the provider context, factory and migration hosted service; use the WithMsSqlStore registration to select it as the key store as well. At host start, IdempotencyMigrationHostedService<TContext>.StartAsync applies pending migrations. Store operations also perform a defensive pending-migration check, remembered per connection string within each closed generic store type and guarded by a semaphore.

Column or index Shared mapping
Id GUID primary key, created with Guid.CreateVersion7().
IdempotentKey Required non-Unicode string, maximum 500.
Endpoint / Method Required strings, maximum 250 / 20; method non-Unicode.
CompositeKey Required Unicode string, maximum 128; stores 64-character uppercase SHA-256 hex.
StatusCode Required integer, provider check constraint CK_StatusCode_Valid for 100–599.
Body Unicode, configured maximum 1,048,576; SQL column type comes from the provider.
ContentType Nullable non-Unicode string, maximum 256.
CreatedAt / ExpiresAt Timestamp / nullable timestamp.
UX_CompositeKey Unique composite-hash lookup index.
Expiry index EF index on ExpiresAt for queries and external cleanup.

Only the lookup identity is hashed. The raw client key, route template and method are retained as columns.

🧱 Where it fits

The package overview shows the host registrations and dependencies behind this capability. The core filter and selected store have separate responsibilities.

The consumer host selects this package’s components and supplies the runtime dependencies shown in the package architecture.

⚠️ Gotchas & limits