Stella.MinimalApi 2.0.1

dotnet add package Stella.MinimalApi --version 2.0.1
                    
NuGet\Install-Package Stella.MinimalApi -Version 2.0.1
                    
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="Stella.MinimalApi" Version="2.0.1" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Stella.MinimalApi" Version="2.0.1" />
                    
Directory.Packages.props
<PackageReference Include="Stella.MinimalApi" />
                    
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 Stella.MinimalApi --version 2.0.1
                    
#r "nuget: Stella.MinimalApi, 2.0.1"
                    
#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 Stella.MinimalApi@2.0.1
                    
#: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=Stella.MinimalApi&version=2.0.1
                    
Install as a Cake Addin
#tool nuget:?package=Stella.MinimalApi&version=2.0.1
                    
Install as a Cake Tool

Stella.MinimalApi

A lightweight, modular endpoint discovery library for ASP.NET Core Minimal APIs.

Stella.MinimalApi scans an assembly for all IEndpoint implementations and automatically maps them at startup โ€” allowing clean, modular, feature-based API architectures.

Perfect for modular monoliths, vertical slice architectures, and clean Minimal API designs.


๐Ÿš€ Installation

dotnet add package Stella.MinimalApi

Option 2 โ€” Inline Single-File Version (zero dependencies)

If you prefer not to install a package, you can simply copy this single file directly into your project:

<details> <summary><strong>Click to expand: MinimalApiExtensions.cs</strong></summary>

// MinimalApiExtensions.cs (inline version)

using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Routing;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.DependencyInjection.Extensions;
using System.Reflection;

namespace Stella.MinimalApi;

public interface IEndpoint
{
    void MapEndpoint(IEndpointRouteBuilder app);
}

public static class MinimalApiExtensions
{
    public static IServiceCollection AddEndpoints(this IServiceCollection services, Assembly assembly)
    {
        var descriptors = assembly
            .DefinedTypes
            .Where(t => !t.IsAbstract && !t.IsInterface && typeof(IEndpoint).IsAssignableFrom(t))
            .Select(t => ServiceDescriptor.Transient(typeof(IEndpoint), t))
            .ToArray();

        services.TryAddEnumerable(descriptors);
        return services;
    }

    public static WebApplication MapEndpoints(
        this WebApplication app,
        RouteGroupBuilder? routeGroupBuilder = null)
    {
        var endpoints = app.Services.GetRequiredService<IEnumerable<IEndpoint>>();
        IEndpointRouteBuilder builder = routeGroupBuilder ?? app;

        foreach (var ep in endpoints)
            ep.MapEndpoint(builder);

        return app;
    }
}

</details>


๐Ÿ“ Quick Example

1. Define an endpoint

public class UserGetEndpoint : IEndpoint
{
    public void MapEndpoint(IEndpointRouteBuilder app)
    {
        app.MapGet("/users/{id:int}", (int id) => $"User {id}");
    }
}

2. Register endpoints from an assembly

builder.Services.AddEndpoints(typeof(UserGetEndpoint).Assembly);

3. Map endpoints at startup

var app = builder.Build();

app.MapEndpoints();      // auto-maps all IEndpoint implementations

app.Run();

(Optional) group endpoints under a common prefix:

app.MapEndpoints(app.MapGroup("/api"));

๐Ÿ“ Example Project Structure

src/
  MyApi/
    Program.cs
    Modules/
      Users/
        UserGetEndpoint.cs
        UserCreateEndpoint.cs
      Billing/
        BillingGetEndpoint.cs
  Stella.MinimalApi/
    IEndpoint.cs
    MinimalApiExtensions.cs

This works extremely well in feature-based or DDD-inspired designs.


๐Ÿง  How It Works

  • Discovers all types implementing IEndpoint in the provided assembly
  • Registers each endpoint as a transient service
  • Resolves and maps them during app startup
  • Enables clean modularity without manual wiring

๐Ÿงช Testing Example

[Fact]
public void AddEndpoints_ShouldRegisterAllImplementations()
{
    var services = new ServiceCollection();
    var assembly = typeof(TestEndpoint).Assembly;

    services.AddEndpoints(assembly);
    var provider = services.BuildServiceProvider();

    provider.GetServices<IEndpoint>()
            .Should().ContainSingle()
            .Which.Should().BeOfType<TestEndpoint>();
}

๐Ÿ“œ License

This project is released into the public domain via the Unlicense. You may freely copy, reuse, modify, inline, or distribute this code โ€” including using it without attribution or embedding it directly inside your project.

Open to contributions and improvements. Enjoy!

Product Compatible and additional computed target framework versions.
.NET net9.0 is compatible.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  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.

NuGet packages (1)

Showing the top 1 NuGet packages that depend on Stella.MinimalApi:

Package Downloads
Stella.MinimalApi.SourceGenerator

Package Description

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
2.0.1 363 12/15/2025
2.0.0 280 12/14/2025
1.0.3 225 12/3/2025
1.0.2 228 12/3/2025
1.0.1 439 8/7/2025
1.0.0 275 8/7/2025