Davish.Endpoints
1.2.0
dotnet add package Davish.Endpoints --version 1.2.0
NuGet\Install-Package Davish.Endpoints -Version 1.2.0
<PackageReference Include="Davish.Endpoints" Version="1.2.0" />
<PackageVersion Include="Davish.Endpoints" Version="1.2.0" />
<PackageReference Include="Davish.Endpoints" />
paket add Davish.Endpoints --version 1.2.0
#r "nuget: Davish.Endpoints, 1.2.0"
#:package Davish.Endpoints@1.2.0
#addin nuget:?package=Davish.Endpoints&version=1.2.0
#tool nuget:?package=Davish.Endpoints&version=1.2.0
Davish.Endpoints
Source-generator-based endpoint discovery and registration for ASP.NET Core Minimal APIs.
Instead of reflection-scanning every loaded assembly at startup to find your endpoint classes, Davish.Endpoints uses a Roslyn incremental source generator to find them at compile time and emit a plain AddEndpoints() registration method. Route mapping (including nested route groups) is then wired up once at startup via a small, bounded reflection pass over the already-resolved instances — not an assembly scan.
Install
dotnet add package Davish.Endpoints
Quick start
Define a group and one or more endpoints that belong to it:
using Davish.Endpoints;
using Microsoft.AspNetCore.Routing;
public class ApiGroup : IGroupEndpoint
{
public RouteGroupBuilder Configure(IEndpointRouteBuilder endpoints)
=> endpoints.MapGroup("api");
}
public class PingEndpoint : IEndpoint<ApiGroup>
{
public void AddRoutes(IEndpointRouteBuilder endpoints)
=> endpoints.MapGet("ping", () => "pong");
}
Wire it up in Program.cs:
using Davish.Endpoints;
var builder = WebApplication.CreateBuilder(args);
builder.Services.AddEndpoints(); // generated at compile time
var app = builder.Build();
app.MapEndpoints(); // maps groups + endpoints, parents before children
app.Run();
GET /api/ping now returns pong.
Nested groups
Groups can be nested by declaring a parent via IGroupEndpoint<TParent>:
public class ApiGroup : IGroupEndpoint
{
public RouteGroupBuilder Configure(IEndpointRouteBuilder endpoints)
=> endpoints.MapGroup("api");
}
public class AuthGroup : IGroupEndpoint<ApiGroup>
{
public RouteGroupBuilder Configure(IEndpointRouteBuilder endpoints)
=> endpoints.MapGroup("auth");
}
public class LoginEndpoint : IEndpoint<AuthGroup>
{
public void AddRoutes(IEndpointRouteBuilder endpoints)
=> endpoints.MapPost("login", () => Results.Ok());
}
POST /api/auth/login is mapped automatically, with ApiGroup configured before AuthGroup.
How it works
AddEndpoints()is generated by a source generator that scans your project for non-abstract classes implementingIEndpoint/IEndpoint<TGroup>andIGroupEndpoint/IGroupEndpoint<TParent>, and registers each one intoIServiceCollectionas a singleton.MapEndpoints()resolves those registered instances from the DI container, inspects each instance's own generic interface arguments once (a small, fixed-size reflection pass — not an assembly scan) to determine group/parent relationships, and callsConfigure/AddRoutesin dependency order.
This split keeps the expensive part (finding all your endpoint types across a potentially large codebase) at compile time, while keeping the cheap part (wiring a handful of already-resolved instances together) as ordinary, easy-to-read runtime code.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net10.0 is compatible. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
-
net10.0
- No dependencies.
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.