Kanject.Core.Api

ASP.NET Core extensions that give every Kanject service the same baseline: structured exception responses, CORS defaults, warm-up endpoints, route prefixing, and predictable problem details.

Install

bash
dotnet add package Kanject.Core.Api

Register

csharp
using Kanject.Core.ApiV2.Extensions;

builder.Services.AddDefaultAppServices();
builder.Services.AddDefaultAppCors(builder.Configuration);

var app = builder.Build();

app.UseCoreExceptionHandlerMiddleware();   // structured JSON error responses
app.UseDefaultAppCors(builder.Configuration);
app.UseAdapterPing();                      // /ping warm-up endpoint
app.UseAuthentication();
app.UseAuthorization();
app.MapControllers();
app.Run();

Error response shape

UseCoreExceptionHandlerMiddleware translates every uncaught exception into RFC 7807 problem-details JSON with a stable traceId:

json
{
  "type": "https://errors.kanject.com/validation",
  "title": "Validation failed",
  "status": 400,
  "errors": {
    "email": ["Email is required."],
    "price": ["Price must be greater than 0."]
  },
  "traceId": "req_01HSXG2..."
}

What ships with it

  • UseCoreExceptionHandlerMiddleware — RFC 7807 problem details for every error
  • AddDefaultAppCors — environment-aware CORS allowlists from appsettings
  • UseAdapterPing/ping warm-up endpoint that survives cold-start probes
  • AddDefaultAppServices — DI registrations every service uses (logging scope, request context)
  • Route-prefix detection for Lambda stage deployments (/dev/api/... vs /api/...)
See also
If you want the one-line setup that bundles Api + Logs + Secrets together, use [Kanject.Core.Adapter](/docs/core-adapter) instead of registering each piece manually.