Framework-agnostic HTTP abstractions for Knight.Response (shared options and validation mapping).
$ dotnet add package Knight.Response.Abstractions.HttpCross‑framework abstractions for HTTP result handling in the Knight.Response family.
This package collects the shared contracts, options, and resolvers that both
Knight.Response.AspNetCore (for modern ASP.NET Core / minimal APIs), andKnight.Response.AspNetCore.Mvc (for legacy ASP.NET Core MVC 2.x / .NET Framework scenarios)use to keep behavior consistent.
Target frameworks: .NET Standard 2.0 (works with .NET Framework 4.7.1+ and .NET Core/.NET 6+).
KnightResponseBaseOptions<TH, TProblem, TValidation>
Base options class that centralizes:
UseProblemDetails (default: false)UseValidationProblemDetails (default: false)IncludeFullResultPayload (default: false, was true before 2.0.0-preview01)IncludeExceptionDetails (default: false)CodeToHttp delegate (optional, domain codes → HTTP codes)StatusCodeResolver delegate (defaults to 400/409/500/200, nullable from 2.0.0-preview03)The generic parameters let each integration plug in the framework’s
own HttpContext type (TH), ProblemDetails type (TProblem),
and ValidationProblemDetails type (TValidation) without duplication.
HTTP mapping defaults and resolvers
KnightResponseHttpDefaults — default mapping from Status to HTTP codes.ResultHttpResolver — unified logic for resolving an HTTP code from a Result,
honoring CodeToHttp first and falling back to StatusCodeResolver.Validation error mapping
IValidationErrorMapper — abstraction for converting domain Messages
into a Dictionary<string,string[]> suitable for validation problems.DefaultValidationErrorMapper — conservative default implementation.dotnet add package Knight.Response.Abstractions.Http
You typically won’t reference this directly in application code; it’s a transitive dependency of the ASP.NET/MVC integration packages. It’s useful if you’re building your own integration and want to align with Knight.Response conventions.
using Knight.Response.Abstractions.Http.Mappers;
public sealed class MyValidationMapper : IValidationErrorMapper
{
public IDictionary<string, string[]> Map(IReadOnlyList<Message> messages)
=> new Dictionary<string, string[]> { ["name"] = new[] { "is required" } };
}
Register this type in the DI container of your chosen integration package
(e.g., Knight.Response.AspNetCore or Knight.Response.Mvc).
using Knight.Response.Models;
using Knight.Response.Abstractions.Http.Options;
services.AddKnightResponse(opts =>
{
opts.CodeToHttp = code => code?.Value switch
{
var v when v == ResultCodes.NotFound.Value => 404,
var v when v == ResultCodes.AlreadyExists.Value => 409,
var v when v == ResultCodes.NoContent.Value => 204,
var v when v == ResultCodes.NotSupported.Value => 405,
_ => null
};
});
Knight.Response — immutable Result / Result<T> core library.Knight.Response.AspNetCore — modern ASP.NET Core + minimal APIs integration.Knight.Response.AspNetCore.Mvc — ASP.NET Core MVC 2.x / .NET Framework–friendly integration.This project is licensed under the MIT License.
Contributions are welcome! Please read CONTRIBUTING.md.