Trellis.Asp.ApiVersioning 3.0.0-alpha.337

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

Trellis.Asp.ApiVersioning

NuGet Package

API-versioning helpers for Trellis.Asp — auto-inject the api-version route value into builder-generated URLs so responses round-trip the requested version under query/header API versioning. Covers Location headers (WithVersionedRoute()) and paginated next-page URLs (HttpContext.PageUrl(...)).

Installation

dotnet add package Trellis.Asp.ApiVersioning

Quick Example

using Trellis;
using Trellis.Asp;
using Trellis.Asp.ApiVersioning;

result.ToHttpResponse(opts => opts
    .CreatedAtRoute("Customers_GetById", c => c.Id.Value)
    .WithVersionedRoute());
//   ↑ Location header includes ?api-version=<requested-version> automatically.

// Paginated list — versioned next-page URL with one helper call:
return pageResult.ToHttpResponse(
    nextUrlBuilder: HttpContext.PageUrl(
        "Orders_GetOverdue",
        (c, applied) => new RouteValueDictionary { ["cursor"] = c.Token, ["limit"] = applied }),
    body: o => OrderListItemResponse.From(o));
//   ↑ next URL carries the api-version, fills URL-segment templates from ambient route data,
//     skips injection on [ApiVersionNeutral] endpoints and on endpoints with no
//     ApiVersionMetadata (unversioned hosts), and URL-encodes the cursor token.

WithVersionedRoute() chains after any builder method that emits a builder-generated Location header — including CreatedAtRoute(...) / CreatedAtAction(...) (201 Created) and WithLocation(...) (2xx state-transition responses on existing resources).

Why

Under query/header API versioning, Location headers from CreatedAtRoute(...) / CreatedAtAction(...) / WithLocation(...) silently omit the api-version parameter unless every author remembers to add it to the route values dictionary — a recurring source of dereference 404s that's invisible without integration tests. WithVersionedRoute() injects the version at request time using the configured IApiVersionReader chain, with sensible fallbacks and explicit failures for ambiguous configurations.

Key Features

  • WithVersionedRoute() composes with CreatedAtRoute(...), CreatedAtAction(...), WithLocation(...), and any other builder-generated Location method
  • HttpContext.PageUrl(routeName, ...) returns a Func<Cursor, int, string> for the nextUrlBuilder parameter of paginated ToHttpResponse(Async) — replaces hand-rolled URL concatenation, version literals, and Uri.EscapeDataString calls with one helper
  • Per-request resolution via httpContext.RequestedApiVersion (the Asp.Versioning.Http extension property), falling back to declared and default versions
  • Explicit-version overloads for both WithVersionedRoute(ApiVersion) and PageUrl(routeName, version, ...) — pin cross-version Location / next-page URLs
  • Honours [ApiVersionNeutral] endpoints and unversioned hosts (endpoints with no ApiVersionMetadata) by skipping injection — applies to all overloads, including explicit pinning. For URL-segment versioning the per-request PageUrl / WithVersionedRoute() overloads and the explicit WithVersionedRoute(ApiVersion) overload skip query injection (ambient routing fills the path segment); the explicit PageUrl(routeName, version, ...) overload throws instead, because silently dropping the pin would let LinkGenerator emit a URL with the wrong path-segment version
  • Logs a single mid-migration warning per (endpoint, AppDomain) pair through the Trellis.Asp.ApiVersioning ILogger category when .WithVersionedRoute() runs against an endpoint with no ApiVersionMetadata (i.e. host removed services.AddApiVersioning(...) but left the chain in place); set TrellisAspOptions.FailFastOnSilentVersionInjection = true (e.g. only in Development) to throw InvalidOperationException on every offending request instead. HttpContext.PageUrl(...) stays silent — its return value is inspected by the caller so a missing api-version is visible there
  • Throws on degenerate configurations (multi-version action with no client-requested version and no DefaultApiVersion) instead of silently picking

Documentation

Part of Trellis

This package is part of the Trellis framework.

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.

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
3.0.0-alpha.337 0 6/3/2026
3.0.0-alpha.336 26 6/3/2026
3.0.0-alpha.304 58 5/29/2026