Skip to content

Introduction

Immediate.Apis turns Immediate.Handlers handlers into ASP.NET Core minimal API endpoints at compile time.

1 min read
Immediate.Apis GitHub repository Immediate.Apis NuGet version Immediate.Apis latest GitHub release Immediate.Apis license

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

A minimal example

GetUsers.cs
[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:

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