StaticEndpoints 1.0.0

dotnet add package StaticEndpoints --version 1.0.0
                    
NuGet\Install-Package StaticEndpoints -Version 1.0.0
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="StaticEndpoints" Version="1.0.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="StaticEndpoints" Version="1.0.0" />
                    
Directory.Packages.props
<PackageReference Include="StaticEndpoints" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add StaticEndpoints --version 1.0.0
                    
#r "nuget: StaticEndpoints, 1.0.0"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package StaticEndpoints@1.0.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=StaticEndpoints&version=1.0.0
                    
Install as a Cake Addin
#tool nuget:?package=StaticEndpoints&version=1.0.0
                    
Install as a Cake Tool

StaticEndpoints

A lightweight, AOT-compatible library for organizing ASP.NET Core minimal API endpoints using source generation.

The library consists of a single, simple interface:

public interface IEndpoint
{
    static abstract void AddRoute(IEndpointRouteBuilder builder);
}

That's it. Implement this interface on your endpoint classes, and the source generator handles the rest.

Features

  • AOT-Compatible: Fully compatible with Native AOT compilation
  • 🚀 Source Generator: Zero runtime reflection - all endpoint registration is generated at compile time
  • 🎯 Type-Safe: Leverage C# static abstract interface members for compile-time safety
  • 📦 Minimal Dependencies: Only depends on ASP.NET Core framework
  • 🏗️ Clean Architecture: Organize endpoints alongside your features with vertical slice architecture

Installation

dotnet add package StaticEndpoints

Quick Start

1. Define an Endpoint

Create a class that implements IEndpoint with a static AddRoute method:

using StaticEndpoints;

namespace MyApp.Features.WeatherForecast;

public class GetWeatherForecast : IEndpoint
{
    public static void AddRoute(IEndpointRouteBuilder builder)
    {
        builder.MapGet("/weatherforecast", HandleAsync)
               .WithName("GetWeatherForecast");
    }

    static WeatherForecast[] HandleAsync()
    {
        var summaries = new[] { "Freezing", "Bracing", "Chilly", "Cool", "Mild" };
        
        return Enumerable.Range(1, 5)
            .Select(index => new WeatherForecast(
                DateOnly.FromDateTime(DateTime.Now.AddDays(index)),
                Random.Shared.Next(-20, 55),
                summaries[Random.Shared.Next(summaries.Length)]
            ))
            .ToArray();
    }

    record WeatherForecast(DateOnly Date, int TemperatureC, string? Summary);
}

2. Register All Endpoints

In your Program.cs, call the auto-generated MapStaticEndpoints() method:

var builder = WebApplication.CreateBuilder(args);

builder.Services.AddOpenApi();

var app = builder.Build();

if (app.Environment.IsDevelopment())
{
    app.MapOpenApi();
}

app.UseHttpsRedirection();
app.MapStaticEndpoints(); // ✨ Auto-discovers and registers all endpoints
app.Run();

That's it! The source generator automatically finds all IEndpoint implementations and generates the registration code.

How It Works

  1. Compile Time: The source generator scans your assembly for all types implementing IEndpoint
  2. Code Generation: It generates a MapStaticEndpoints() extension method that calls each endpoint's AddRoute method
  3. Zero Overhead: No reflection, no runtime discovery - just direct method calls

Generated Code Example

// <auto-generated/>
public static partial class StaticEndpointsBuilderExtensions
{
    public static IEndpointRouteBuilder MapStaticEndpoints(
        this IEndpointRouteBuilder app,
        RouteGroupBuilder? routeGroupBuilder = null)
    {
        var builder = routeGroupBuilder ?? app;
        
        MyApp.Features.WeatherForecast.GetWeatherForecast.AddRoute(builder);
        // ... other endpoints
        
        return app;
    }
}

Advanced Usage

Route Groups

You can use route groups to organize endpoints with common prefixes or policies:

var apiGroup = app.MapGroup("/api")
    .RequireAuthorization();

apiGroup.MapStaticEndpoints();

Requirements

  • .NET 10.0 or later
  • C# 11 or later (for static abstract interface members)

Contributing

Contributions are welcome! Please feel free to submit issues or pull requests.

License

This project is licensed under the MIT License.

Product 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • 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.

Version Downloads Last Updated
1.0.0 288 12/16/2025
0.0.1 266 12/16/2025