Placing all Minimal API route definitions directly inDocumentation Index
Fetch the complete documentation index at: https://mintlify.com/Orbis25/FoundationKit/llms.txt
Use this file to discover all available pages before exploring further.
Program.cs works fine for small projects, but as an application grows the file becomes a maintenance burden. FoundationKit’s IEndpointRouteHandler pattern moves each feature’s routes into its own class, mirroring the organisation you’d use with traditional controllers — but retaining all the performance benefits of Minimal APIs. A single call to UseFoundationKitApiHandlers scans your assembly, finds every handler class, and registers all routes automatically.
The IEndpointRouteHandler interface
IEndpointRouteHandler is a minimal contract from FoundationKit.API.Handlers.EndpointRouteHandler. It declares one method:
UseFoundationKitApiHandlers.
Handler classes must have a parameterless constructor because
EndpointRouteBuilderExtensions.MapEndpoints instantiates them with Activator.CreateInstance(type). If you need services, use [FromServices] parameters on individual route delegates rather than constructor injection on the handler class itself.Creating a handler
Create one class per resource or feature. ImplementMapEndpoints to register all routes for that feature using the standard IEndpointRouteBuilder API:
MapEndpoints call. Group them by resource or use app.MapGroup("/api/people") to share a route prefix:
Registration
CallUseFoundationKitApiHandlers once in Program.cs, passing the assembly that contains your handler classes. The extension method scans the assembly, instantiates every IEndpointRouteHandler, and calls MapEndpoints on each:
UseFoundationKitApiHandlers returns the WebApplication instance, so it can be chained with other middleware calls.
How the scanner works (from EndpointRouteBuilderExtensions):
Combining with inline routes and controllers
Handler-based routes and inlineMapXxx calls coexist naturally on the same WebApplication. The example project uses UseFoundationKitApiHandlers for the PeoplesHandler read endpoint while defining write operations inline:
Handler-based routes
Use
IEndpointRouteHandler classes for stable, resource-level routes that benefit from organisation and discoverability.Inline routes
Keep ephemeral or single-purpose endpoints inline in
Program.cs when they don’t warrant a dedicated handler file.