1

I'm trying to implement api versioning following this tutorial. So in my startup I have:

var constraintResolver = new DefaultInlineConstraintResolver()
{
    ConstraintMap =
    {
        ["apiVersion"] = typeof( ApiVersionRouteConstraint )
    }
};

configuration.MapHttpAttributeRoutes(constraintResolver);
configuration.AddApiVersioning()

and my controllers:

[Route("api/v{version:apiVersion}/my")]
[ApiVersion("1.0")]
[ApiVersion("2.0")]
public class MyV1Controller 

[Route("api/v{version:apiVersion}/my")]
[ApiVersion("3.0")]
public class MyV3Controller 

When I request for http://localhost/api/v1.0/my I get an error

Multiple controller types were found that match the URL. This can happen if attribute routes on multiple controllers match the requested URL.\r\n\r\nThe request has found the following matching controller types: \r\nMyV1Controller\r\nMyV2Controller

Could you please advice how to make controller versioning to work?

krzyszt0fd
  • 86
  • 7

1 Answers1

1

I took a break and I remembered that in my project I have a custom IHttpControllerSelector implementation which extends DefaultHttpControllerSelector.

configuration.Services.Replace(typeof(IHttpControllerSelector), new ApiControllerSelector(config));

After I removed it versioning started to work. Executing configuration.AddApiVersioning sets ApiVersionControllerSelector in ServicesContainer. It was accidently replaced with my custom implementation.

krzyszt0fd
  • 86
  • 7