Stella.MinimalApi
2.0.1
dotnet add package Stella.MinimalApi --version 2.0.1
NuGet\Install-Package Stella.MinimalApi -Version 2.0.1
<PackageReference Include="Stella.MinimalApi" Version="2.0.1" />
<PackageVersion Include="Stella.MinimalApi" Version="2.0.1" />
<PackageReference Include="Stella.MinimalApi" />
paket add Stella.MinimalApi --version 2.0.1
#r "nuget: Stella.MinimalApi, 2.0.1"
#:package Stella.MinimalApi@2.0.1
#addin nuget:?package=Stella.MinimalApi&version=2.0.1
#tool nuget:?package=Stella.MinimalApi&version=2.0.1
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
Option 1 โ Install via NuGet (recommended)
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
IEndpointin 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 | Versions 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. |
-
net9.0
- JetBrains.Annotations (>= 2025.2.4)
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.