J'ai configuré avec succès le versionnement de l'API dans mon projet d'API Core 2.1.
http://localhost:8088/api/Camps/ATL2016/speakers?api-version=x.x
Versions 1.1
y 2.0
travailler mais 1.0
échoue en raison d'une ambiguïté sur le Get(string, bool)
Actions.
ASP.NET Core Serveur Web :
MyCodeCamp> fail: Microsoft.AspNetCore.Mvc.Routing.DefaultApiVersionRoutePolicy[1] MyCodeCamp> Request matched multiple actions resulting in ambiguity. Matching actions: MyCodeCamp.Controllers.Speakers2Controller.Get(string, bool) (MyCodeCamp) MyCodeCamp> MyCodeCamp.Controllers.SpeakersController.Get(string, bool) (MyCodeCamp) MyCodeCamp> fail: Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware[1] MyCodeCamp> An unhandled exception has occurred while executing the request. MyCodeCamp> Microsoft.AspNetCore.Mvc.Internal.AmbiguousActionException: Multiple actions matched. The following actions matched route data and had all constraints satisfied:
Contrôleur Speakers2
est décoré de [ApiVersion("2.0")]
Il s'agit donc Get(string, bool)
L'action est la version 2.0, alors pourquoi l'action ne peut-elle pas être mise en œuvre ? Versioning
les différencier ?
Microsoft.AspNetCore.Mvc.Versioning 3.0.0
(impossible d'installer une version supérieure en raison de conflits de versions)
Startup.cs :
services.AddApiVersioning(cfg =>
{ cfg.DefaultApiVersion = new ApiVersion(1, 1);
cfg.AssumeDefaultVersionWhenUnspecified = true;
cfg.ReportApiVersions = true; });
Contrôleurs :
[Route("api/camps/{moniker}/speakers")]
[ValidateModel]
[ApiVersion("1.0")]
[ApiVersion("1.1")]
public class SpeakersController : BaseController
{
. . .
[HttpGet]
[MapToApiVersion("1.0")]
public IActionResult Get(string moniker, bool includeTalks = false)
[HttpGet]
[MapToApiVersion("1.1")]
public virtual IActionResult GetWithCount(string moniker, bool includeTalks = false)
[Route("api/camps/{moniker}/speakers")]
[ApiVersion("2.0")]
public class Speakers2Controller : SpeakersController
{
...
public override IActionResult GetWithCount(string moniker, bool includeTalks = false)