LagomEndpoints 0.0.9

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

LagomEndpoints

One class per endpoint, constructor injection, and a source generator that writes the binding and the registration at build time. No reflection at startup, and it publishes with Native AOT.

// GetOrder.cs
public sealed record GetOrderRequest
{
    public Guid Id { get; init; }              // route, matched by name
    public bool IncludeLines { get; init; }    // query
}

public sealed record GetOrderResponse(Guid Id, string Customer);

[HttpGet("/orders/{id:guid}")]
public sealed partial class GetOrder(OrderStore orders)
    : ILagomEndpoint<GetOrderRequest, Results<Ok<GetOrderResponse>, NotFound>>
{
    public ValueTask<Results<Ok<GetOrderResponse>, NotFound>> HandleAsync(GetOrderRequest request, CancellationToken ct) => ...
}
builder.Services.AddShopApiLagomEndpoints();   // generated: AddScoped for every endpoint
app.MapShopApiLagomEndpoints();                // generated: maps every endpoint

Status: M0 spike

Works today:

  • [HttpGet("template")], [HttpPost], [HttpPut], [HttpPatch], [HttpDelete] and [AcceptVerbs("GET", "HEAD", Route = "template")] (one route for all its methods), several per class. They are shaped like ASP.NET Core MVC's attributes of the same names, and so are [FromRoute], [FromQuery] and [FromHeader] with their Name property, so endpoint code reads the same as controller code.
  • Use the attributes from LagomEndpoints: one using LagomEndpoints; covers the route and the binding attributes, and the file does not need using Microsoft.AspNetCore.Mvc;. MVC's [FromRoute], [FromQuery] and [FromHeader] keep working (written in full, or in a file without our namespace). A file that imports both namespaces gets CS0104 (ambiguous reference) on [HttpGet], [FromQuery] and the rest; drop the MVC import, or, if the file truly needs it, alias ours (using HttpGetAttribute = LagomEndpoints.HttpGetAttribute;, and the same for each binding attribute it uses). MVC's own [HttpGet] or [AcceptVerbs] on an endpoint class is reported as LAGOM012, which says which attribute to use.
  • ILagomEndpoint<TResult> and ILagomEndpoint<TRequest, TResult>. Implementing one of them is what makes a class an endpoint; the route attribute says where it is mapped and is required. Route attributes are not inherited, so every concrete endpoint class needs its own. Endpoints are sealed partial classes: partial because LagomEndpoints generates result helpers into each endpoint class (they arrive in M2; requiring partial now means endpoints written today keep compiling then), so the class and every type that contains it must be partial (LAGOM011).
  • Binding from route, query and headers for strings, anything IParsable<T>, enums and their nullable forms. [FromRoute], [FromQuery], [FromHeader] and [FromForm] override the default source and name (Name = "..."); more than one binding attribute on a property is LAGOM014. A route attribute without a template, or [AcceptVerbs] without a Route or a method, is LAGOM013.
  • Arrays, List<T> and the collection interfaces an array implements (IReadOnlyList<T>, IEnumerable<T> and so on) bind every value of a repeated query key, header, form field or claim: ?status=pending&status=shipped. Route values are single.
  • JSON body binding for POST, PUT and PATCH: the request object is read from the body with the app's HTTP JSON options, then route, query and header values are applied on top. Positional records work here.
  • [FromBody] on one property reads the whole JSON body into it instead; the request's other properties then default to the query string. The body is required unless the property is nullable.
  • Forms and files: an IFormFile or IFormFileCollection property, or [FromForm] on any property, makes the request a form. Its other properties then default to form fields, a request that is not a form gets 415, and the endpoint requires an antiforgery token, as in Minimal APIs. Call endpoint.DisableAntiforgery() in Configure for an API that is not called from browser forms.
  • [FromClaim("sub")] binds a claim of the current user, parsed like a query value. Services are not bound onto a request: take them in the endpoint's constructor (MVC's [FromServices] on a request property is LAGOM021).
  • Requests are created by the generated code with their parameterless constructor, or with their one constructor whose parameters match properties, as a positional record's do: record DeleteOrderRequest(Guid Id). A constructor parameter is required unless it is nullable or has a default value, which is used when the value is not sent.
  • Binding failures return a 400 application/problem+json listing every error. A body that is not JSON returns 415.
  • Diagnostics LAGOM001 to LAGOM008, LAGOM020 and LAGOM021 from an analyzer, for endpoints the generator cannot generate code for. LAGOM005 is a request that reads the body twice (two [FromBody] properties, or one with form values), and LAGOM020 a body or form value on an endpoint that only answers GET, HEAD or DELETE. The generator and the analyzer share one parser, so they always agree on which endpoints are valid.
  • LAGOM009 (warning) for JSON types missing from your JsonSerializerContext, only in projects that need one (see below).
  • LAGOM010 for an endpoint class (one that implements ILagomEndpoint) without a route attribute, which would otherwise silently never be mapped (its message names the LagomEndpoints namespace, since MVC has attributes with the same names). LAGOM001 is the reverse: a route attribute on a class that does not implement exactly one ILagomEndpoint interface. Abstract and generic classes are endpoint bases, not endpoints, and are not asked for a route.
  • Endpoint groups with a route prefix and shared conventions, and a Configure hook on endpoints (see below). LAGOM015 to LAGOM019 cover group cycles, [Route] on an endpoint, a Configure with the wrong signature, [EndpointGroup] or [Route] on a class that is neither an endpoint nor a group, and MVC's [Route] on a group.
  • One NuGet package, LagomEndpoints, with the generator and the analyzer inside it.

Not yet: behaviors, result helpers, OpenAPI metadata.

Groups

A group is a class that implements ILagomEndpointGroup. Its route prefix is an optional [Route("...")], the way an MVC controller has one, and an optional public static void Configure(RouteGroupBuilder group) adds conventions such as authorization, tags, rate limiting or endpoint filters. An endpoint joins a group with [EndpointGroup<T>], written above the route attribute, and its route is relative to the group. Groups nest the same way.

[Route("/api")]
public sealed class ApiGroup : ILagomEndpointGroup
{
    public static void Configure(RouteGroupBuilder group) => group.RequireAuthorization();
}

[EndpointGroup<ApiGroup>]
[Route("/orders")]
public sealed class OrdersGroup : ILagomEndpointGroup
{
    public static void Configure(RouteGroupBuilder group) => group.WithTags("Orders");
}

[EndpointGroup<OrdersGroup>]
[HttpGet("/{id:guid}")]                  // GET /api/orders/{id:guid}
public sealed partial class GetOrder(OrderStore orders)
    : ILagomEndpoint<GetOrderRequest, Results<Ok<GetOrderResponse>, NotFound>>
{
    // Optional: conventions for this endpoint only. Runs once for each route attribute.
    public static void Configure(RouteHandlerBuilder endpoint) => endpoint.WithName("GetOrder");

    public ValueTask<Results<Ok<GetOrderResponse>, NotFound>> HandleAsync(GetOrderRequest request, CancellationToken ct) => ...
}

The generated Map{Assembly}LagomEndpoints calls MapGroup once for each group, inside its parent group, runs the group's Configure once on that builder, and maps each endpoint into its innermost group. So a group's conventions apply to every endpoint in it and in the groups nested in it, and endpoint filters added there run for those endpoints, under Native AOT too.

  • An attribute argument is a constant, so the generator knows the full route of every endpoint at build time. The compiler keeps it in the assembly, so groups can also live in another project than their endpoints. A group without [Route] only shares its conventions.
  • [Route] only goes on groups. On an endpoint it is LAGOM016: put the whole route in [HttpGet] and friends, or use a group. MVC's [Route] compiles on a group class but means nothing here, so it is LAGOM019. A file that imports both LagomEndpoints and Microsoft.AspNetCore.Mvc gets CS0104 on [Route], like on [HttpGet].
  • Route parameters in a prefix ("/tenants/{tenantId}") are bound to the request like any other route value, and a missing request property is LAGOM002.
  • A group that ends up inside itself is LAGOM015. A Configure with another signature, for example an instance method, would never be called, so it is LAGOM017. [EndpointGroup<T>] or [Route] on a class that is neither an endpoint nor a group is LAGOM018.
  • Both Configure methods are optional static virtual members of ILagomEndpointGroup and ILagomEndpoint, so IntelliSense shows them, and a class that leaves them out compiles as before.

Request and response types next to the endpoint

The recommended layout is one file per endpoint, named after it, with the request and response types declared above the endpoint class as <Endpoint>Request and <Endpoint>Response (GetOrder.cs holds GetOrderRequest, GetOrderResponse and GetOrder). Nested Request and Response types inside the endpoint class work just as well; the generator and the analyzers support both.

StyleCop would report the colocated layout as SA1402 (one type per file) and SA1649 (file name must match the first type). The LagomEndpoints package includes a diagnostic suppressor that suppresses exactly those two rules for top-level types named after an endpoint in the same file plus an allowed suffix (LAGOMS001 for SA1402, LAGOMS002 for SA1649; the latter only when the file is named after an endpoint in it). Any other extra type in the file is still reported. Request and Response are always allowed; add more suffixes in .editorconfig:

[*.cs]
lagom_endpoints.additional_colocated_type_suffixes = Item, Mapper, Validator

The suppressor works by rule id, wherever analyzers run (the IDE and the build). It still applies when TreatWarningsAsErrors or an .editorconfig severity of error raises the two rules to errors; Roslyn only refuses to suppress rules whose default severity is error, and SA1402 and SA1649 are warnings by default.

JSON and JsonSerializerContext

A normal ASP.NET Core app needs no JsonSerializerContext. Request bodies and JSON results go through the app's HTTP JSON options, and by default those resolve any type through reflection. samples/TodoApi works this way.

You need a context only when reflection-based JSON is off: with Native AOT (PublishAot) or trimming (PublishTrimmed), or in a library that says it is IsAotCompatible or IsTrimmable. List every type an endpoint reads from or writes to JSON, and add the context in front of the default resolver, as samples/ShopApi does:

[JsonSerializable(typeof(CreateOrderRequest))]
[JsonSerializable(typeof(CreateOrderResponse))]
internal sealed partial class ShopApiJsonContext : JsonSerializerContext;

builder.Services.ConfigureHttpJsonOptions(options =>
    options.SerializerOptions.TypeInfoResolverChain.Insert(0, ShopApiJsonContext.Default));

In those projects, and only there, the analyzer reports LAGOM009 (warning) for each type an endpoint needs that no [JsonSerializable(typeof(...))] in the project lists:

'CreateOrderRequest' is read from JSON by 'CreateOrder', but no JsonSerializerContext in this project lists it; with Native AOT or trimming there is no reflection fallback, so add [JsonSerializable(typeof(CreateOrderRequest))] to a JsonSerializerContext and register it with ConfigureHttpJsonOptions

The types it checks are the request type when it is read from the body, and the T of Ok<T>, Created<T>, CreatedAtRoute<T>, Accepted<T>, AcceptedAtRoute<T>, JsonHttpResult<T>, BadRequest<T>, NotFound<T>, Conflict<T>, UnprocessableEntity<T> and InternalServerError<T>, also inside Results<...>. The package's build/LagomEndpoints.props makes PublishAot, IsAotCompatible, PublishTrimmed and IsTrimmable visible to the analyzer. If a type is still missing at runtime, the error says whether to list it in the context (AOT, trimming) or to stop replacing the default resolver (everything else).

Layout

Path What
src/LagomEndpoints Runtime: interfaces, route attributes, binding helpers
src/LagomEndpoints.Generators The incremental source generator; reports no diagnostics
src/LagomEndpoints.Analyzers The analyzer that reports LAGOM001 to LAGOM021, and the colocated type suppressor
src/LagomEndpoints.Shared Endpoint parsing and models, compiled into both the generator and the analyzer (no project of its own)
samples/ShopApi Sample API, Native AOT enabled, with a JsonSerializerContext
samples/TodoApi Sample API without Native AOT and without a JsonSerializerContext
tests/LagomEndpoints.Generators.Tests Generator output, registration and caching tests, and Verify snapshots of the generated code in Snapshots/
tests/LagomEndpoints.Analyzers.Tests Diagnostic and suppressor tests
tests/ShopApi.Tests HTTP tests against the AOT sample
tests/TodoApi.Tests HTTP tests against the sample without a context

Commands

dotnet test
dotnet run --project samples/ShopApi
dotnet run --project samples/TodoApi
dotnet publish samples/ShopApi -c Release -r win-x64

Generated code for the sample lands in samples/ShopApi/obj/generated.

License

Apache-2.0

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
0.0.9 0 11/24/2026
0.0.8 32 11/24/2026
0.0.7 52 11/23/2026
0.0.6 48 11/23/2026
0.0.5 53 11/23/2026
0.0.4 55 11/23/2026
0.0.3 62 11/23/2026
0.0.2 55 11/23/2026
0.0.1 52 11/23/2026