Skip to content

Add Versioning Support via Asp.Versioning#422

Open
jayharris wants to merge 4 commits intoivaylokenov:developmentfrom
jayharris:fork-issue421-apiVersioningSupport
Open

Add Versioning Support via Asp.Versioning#422
jayharris wants to merge 4 commits intoivaylokenov:developmentfrom
jayharris:fork-issue421-apiVersioningSupport

Conversation

@jayharris
Copy link

@jayharris jayharris commented Feb 22, 2026

Overview

  • Revise API Versioning Support from Microsoft.AspNetCore.Mvc.Versioning v5.1.0 to Asp.Versioning.Mvc v8.1.1
  • Add Support for HTTP Header version resolution
  • Add support for developer-defined querystring or HTTP Header version-resolution keys.

This will close #421

Details

The MyTested.AspNetCore.Mvc.Versioning plugin currently depends on the deprecated Microsoft.AspNetCore.Mvc.Versioning v5.1.0. The replacement package is Asp.Versioning.Mvc, currently in v8.1.1. The challenge is that the old package registered a custom ApiVersionActionSelector as IActionSelector which handled version-aware action filtering in the legacy routing pipeline. The new package no longer provides this; it relies on ApiVersionMatcherPolicy via endpoint routing. Since MyTested disables endpoint routing (EnableEndpointRouting = false), version filtering won't happen, causing ambiguous match errors.

The solution is to swap packages to Asp.Versioning.Mvc, update namespaces, and implement a custom IActionSelector decorator in the plugin that restores version-aware action selection.

Further Enhancements

Further, because Asp.Versioning allows developers to resolve version by HTTP Header, and also allows developers to configure custom keys via ApiVersioningOptions.ApiVersionReader (e.g., QueryStringApiVersionReader("v"), HeaderApiVersionReader("X-Custom-Version")), we have enhanced the GetRequestedApiVersion methods to support Header resolution and to read the configured keys from the library's own IApiVersionReader at request time using IOptions<ApiVersioningOptions>.

…g to Asp.Versioning.Mvc

Replace deprecated Microsoft.AspNetCore.Mvc.Versioning v5.1.0 with
Asp.Versioning.Mvc v8.1.1 and update all namespace references from
Microsoft.AspNetCore.Mvc.Versioning to Asp.Versioning across plugin
source and test projects.
Asp.Versioning.Mvc no longer provides a custom IActionSelector for
legacy routing (it relies on endpoint routing middleware instead).
Since MyTested disables endpoint routing, this adds:
- ApiVersionActionConstraint: filters actions during route matching
  to prevent ambiguous match errors on versioned controllers
- ApiVersionActionConstraintProvider: registers the constraint for
  actions with API version metadata
- ApiVersionAwareActionSelector: decorator around IActionSelector
  that filters candidates by requested API version for query string
  versioning scenarios
- Updated VersioningTestPlugin to implement IServiceRegistrationPlugin
  and IRoutingServiceRegistrationPlugin for proper service registration
…ng controller tests

Add support for reading API version from x-api-version request header
in both ApiVersionAwareActionSelector and ApiVersionActionConstraint.

Extend test coverage with 24 new tests covering:
- Header-based version routing and pipeline assertions
- Version-neutral controllers for query-string and header routing
- Multiple controllers competing for the same route at different
  versions across URL-segment, query-string, and header strategies
…dcoded keys

Replace hardcoded query string ("api-version") and header
("x-api-version") version extraction with the user-configured
IApiVersionReader resolved from IOptions<ApiVersioningOptions>.

This ensures the plugin respects custom reader keys configured via
AddApiVersioning(). Tests updated to use non-default keys ("v" for
query string, "X-Custom-Version" for header) to prove the
configuration is honored.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support Asp.Versioning in AspNetCore v6+

1 participant