Implementing URI versioning
URI versioning can be implemented either manually via route templates or formally using the Asp.Versioning.Mvc package (a replacement for the deprecated Microsoft.AspNetCore.Mvc.Versioning package). Asp.Versioning.Mvc is widely used and maintained by the same author (Chris Martinez) and is fully aligned with current .NET ecosystem best practices.
Using this package gives you a cleaner, extensible, and industry-standard way to manage API versions with features like:
- Version negotiation (via URI, query string, or header)
- Automatic version discovery
- Versioned controllers
It works by decorating the controller class with [ApiVersion] and specifying versioned route templates with {version:apiVersion}.
Adding versions to the customers web service
Let’s see a practical example:
- In the
Northwind.WebApiproject, add a reference to the packages for versioning and its integration with API Explorer, as shown...