DKNet

Read and delete entities through specifications

Part of DKNet.AspCore.Extensions. These mappers call IRepositorySpec directly. Register the repository and a relational DbContext before serving them. This example maps routes without sending database requests:

using DKNet.AspCore.Extensions.Endpoints;
using DKNet.EfCore.Abstractions.Entities;
var builder = WebApplication.CreateBuilder(args);
var app = builder.Build();
var group = app.MapGroup("/items");
group.MapGetById<Item, int, ItemModel>();
group.MapGetList<Item, int, ItemModel>("/");
group.MapDeleteById<Item, int>();
Console.WriteLine("Item routes mapped; register AddSpecRepo<TDbContext>() before serving.");
public sealed class Item : IEntity<int> { public int Id { get; set; } }
public sealed class ItemModel { public int Id { get; set; } }

The delete mapper looks up an entity, returns 404 when absent, or deletes and saves through the repository with a 409 save-failure branch.

MapGetById<TEntity,TKey,TModel> defaults to {id} and returns a projected model (200) or 404. MapGetList<TEntity,TKey,TModel> defaults to / and returns a paged projection or 400 for an unusable list query. MapDeleteById<TEntity,TKey> defaults to {id}, loads the entity, deletes through the repository and calls SaveChangesAsync; it returns 204, 404 for no match, or 409 on DbUpdateException from saving.

Each has a Guid-key shorthand omitting TKey. Explicit keys must implement IEquatable<TKey> and be bindable by minimal APIs; models must be classes. The three-type MapDeleteById<TEntity,TKey,TRequest> binds a class implementing Fluents.Requests.IWithKey<TKey> with [AsParameters]. It lets a host validation filter refuse a delete before the shared save helper runs, without adding a request body.

Deletes use the repository save pipeline, including any configured audit/domain-event hooks. They are hard deletes, subject to the repository and database behavior.

🧱 Where it fits

Register AddSpecRepo<TDbContext>() from EF Core Specifications. For list inputs see query list endpoints. The package component diagram shows the repository path alongside SlimMessageBus dispatch.

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

⚠️ Gotchas & limits