Introduction
Immediate.Apis turns Immediate.Handlers handlers into ASP.NET Core minimal API endpoints at compile time.
Immediate.Apis is a source generator that bridges Immediate.Handlers to ASP.NET Core minimal APIs. Add a [MapGet] (or [MapPost], [MapPut], …) attribute alongside [Handler], and the generator emits the app.MapGet(...) call, the request-binding attribute, the
authorization conventions and an assembly-wide registration method — all at compile time, with no
reflection and no runtime endpoint scanning.
Installation
dotnet add package Immediate.Apis - Immediate.Handlers is required and is pulled in as a package dependency. Every endpoint is a
handler first: the class must carry
[Handler], or the generator emits nothing and IAPI0001 is reported as an error. - An ASP.NET Core project. The generated code calls into
Microsoft.AspNetCore.BuilderandMicrosoft.AspNetCore.Routing, which come from the ASP.NET Core shared framework. - The package targets
net8.0,net9.0andnet10.0.
A minimal example
[Handler]
[MapGet("/users")]
public static partial class GetUsers
{
public sealed record Query;
private static ValueTask<IEnumerable<User>> HandleAsync(
Query _,
UsersService usersService,
CancellationToken token
)
{
return usersService.GetUsersAsync(token);
}
}Then register everything once in Program.cs:
var builder = WebApplication.CreateBuilder(args);
builder.Services.AddUsersApiHandlers();
var app = builder.Build();
app.MapUsersApiEndpoints();
app.Run();AddUsersApiHandlers comes from Immediate.Handlers; MapUsersApiEndpoints comes from Immediate.Apis.
Both are named from the assembly identifier — here, a project
named Users.Api.
Where to next
Verb attributes, multiple routes, route constraints, and registration.
How the generator decides between [FromBody] and [AsParameters].
[Authorize], [AllowAnonymous], and the policy-only restriction.
CustomizeEndpoint, TransformResult, and metadata attributes.
Share a prefix and configuration across a set of endpoints.
Register a subset of your endpoints per host, per environment or per test.
Unique schema IDs for nested request types, in Swashbuckle and in Microsoft.AspNetCore.OpenApi.
Every attribute the generator reads, with its exact shape.
The members the generator emits, including Route and Routes.
IAPI0001–IAPI0013, their severities and their code fixes.