Trellis.Asp.ApiVersioning
3.0.0-alpha.337
dotnet add package Trellis.Asp.ApiVersioning --version 3.0.0-alpha.337
NuGet\Install-Package Trellis.Asp.ApiVersioning -Version 3.0.0-alpha.337
<PackageReference Include="Trellis.Asp.ApiVersioning" Version="3.0.0-alpha.337" />
<PackageVersion Include="Trellis.Asp.ApiVersioning" Version="3.0.0-alpha.337" />
<PackageReference Include="Trellis.Asp.ApiVersioning" />
paket add Trellis.Asp.ApiVersioning --version 3.0.0-alpha.337
#r "nuget: Trellis.Asp.ApiVersioning, 3.0.0-alpha.337"
#:package Trellis.Asp.ApiVersioning@3.0.0-alpha.337
#addin nuget:?package=Trellis.Asp.ApiVersioning&version=3.0.0-alpha.337&prerelease
#tool nuget:?package=Trellis.Asp.ApiVersioning&version=3.0.0-alpha.337&prerelease
Trellis.Asp.ApiVersioning
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 withCreatedAtRoute(...),CreatedAtAction(...),WithLocation(...), and any other builder-generated Location methodHttpContext.PageUrl(routeName, ...)returns aFunc<Cursor, int, string>for thenextUrlBuilderparameter of paginatedToHttpResponse(Async)— replaces hand-rolled URL concatenation, version literals, andUri.EscapeDataStringcalls with one helper- Per-request resolution via
httpContext.RequestedApiVersion(theAsp.Versioning.Httpextension property), falling back to declared and default versions - Explicit-version overloads for both
WithVersionedRoute(ApiVersion)andPageUrl(routeName, version, ...)— pin cross-version Location / next-page URLs - Honours
[ApiVersionNeutral]endpoints and unversioned hosts (endpoints with noApiVersionMetadata) by skipping injection — applies to all overloads, including explicit pinning. For URL-segment versioning the per-requestPageUrl/WithVersionedRoute()overloads and the explicitWithVersionedRoute(ApiVersion)overload skip query injection (ambient routing fills the path segment); the explicitPageUrl(routeName, version, ...)overload throws instead, because silently dropping the pin would letLinkGeneratoremit a URL with the wrong path-segment version - Logs a single mid-migration warning per
(endpoint, AppDomain)pair through theTrellis.Asp.ApiVersioningILoggercategory when.WithVersionedRoute()runs against an endpoint with noApiVersionMetadata(i.e. host removedservices.AddApiVersioning(...)but left the chain in place); setTrellisAspOptions.FailFastOnSilentVersionInjection = true(e.g. only in Development) to throwInvalidOperationExceptionon every offending request instead.HttpContext.PageUrl(...)stays silent — its return value is inspected by the caller so a missingapi-versionis 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 | Versions 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. |
-
net10.0
- Asp.Versioning.Http (>= 10.0.0)
- Asp.Versioning.Mvc (>= 10.0.0)
- Asp.Versioning.Mvc.ApiExplorer (>= 10.0.0)
- Trellis.Asp (>= 3.0.0-alpha.337)
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 |