aspnet/AspNetWebStack

Question: centralizing versions for easier updating/maintenance

nlersber opened this issue · 1 comments

In what way can versioning be centralized to a single location in a project? Currently, we have set up each of our controllers in our web API to have the versions defined and each endpoint is annotated with the versions that can be mapped to those methods.

    [ApiVersion("1.0")]
    public class ExampleController : QueryApiControllerBase
{
    [HttpGet]
    [Route("EndpointMethod")]
    [Route("v{version:apiVersion}/EndpointMethod")]
    [MapToApiVersion("1.0")]
    public async Task<IHttpActionResult> EndpointMethod()
    {
        return Foo();
    }
}

With a very simple setup in the HttpConfiguration as well:

this.AddApiVersioning(options =>
    {
         options.AssumeDefaultVersionWhenUnspecified = true;
         options.DefaultApiVersion = new ApiVersion(2, 0);
    });

Since our project is fairly large with a lot of controllers, doing a version update requires a huge effort to add the new version to every single controller and endpoint, even though all of em are virtually the same and only a couple of endpoints might deviate from the norm. Is there a way to centralize this and define all versions by default, unless it is specifically set up to only allow specific versions? So far I have tried creating a wrapper for [ApiVersion] to allow for inheritance and put this on my QueryApiControllerBase, but that resulted in no version:apiVersion being available and thus multiple methods with the same route besides the version being incompatible with our Swagger setup.

Due to 99% of our API being compatible with all possible versions, it is an incredible hassle to add annotations to everything. Can this be centralized in a some way?

Looks like it auto posted it here instead of the correct package. Will repost there and close this.