Support Method-Level Versioning
The ApiVersionAttribute is a very user-friendly paradigm, but it only targets the class level. It would be great if I could version controller methods individually.
Here's my scenario: I typically need to support two parallel versions of an endpoint while all of my clients are transitioning. The controller that services the original endpoint already has the dependencies necessary to fulfill its job. It may also have internal/private helper methods, etc. If I'm forced to version at the Controller level, I have an explosion of classes (controllers) as I introduce versions. I'd rather have an explosion of methods with a stable number of classes.
So rather than:
[ApiVersion( "1.0" )]
public class PeopleController : Controller
{
_peopleDataAccess;
[HttpGet]
[Route( "people" )]
public IActionRoute Get() => Ok( _peopleDataAccess.GetPeopleV1() );
}
// Note how this 2nd guy is identical to 1st, except for the data access method it calls.
[ApiVersion( "2.0" )]
public class People2Controller : Controller
{
_peopleDataAccess;
[HttpGet]
[Route( "people" )]
public IActionRoute Get() => Ok( _peopleDataAccess.GetPeopleV2() );
}
I'd rather have a single class like so:
[Route( "people" )]
public class PeopleController : Controller
{
_privateDataAccess;
[HttpGet]
[ApiVersion( "1.0" )]
public IActionRoute Get() => Ok( _peopleDataAccess.GetPeopleV1() );
[HttpGet]
[ApiVersion( "2.0" )]
public IActionRoute Get() => Ok( _peopleDataAccess.GetPeopleV2() );
}
Nevermind, I'll RTFM. :-)
https://github.com/Microsoft/aspnet-api-versioning/wiki/Version-Interleaving
Glad you figured it out. Under the hood, the behaviors are really almost the same. In earlier, internal versions of the library, there was often confusion about the differences of the ApiVersionAttribute at the controller-level vs the action-level. For clarity, I eventually agreed to add a new action-level attribute with the name MapToApiVersionAttribute so that it's clear that an API version maps to an action, but the actual API version of the service is defined at the controller-level.
Hopefully that makes sense. Let me know if you find the documentation unclear or otherwise lacking.