Skip to content

Versioning

Implement versioning to ensure that the API is backward-compatible and can handle changes without breaking existing integrations. Versioning also makes it easier for developers to choose the version of the API that meets their specific needs.

PSS®X integrates the ASPNET-API-Versioning feature and adapts to C# and JavaScript Static Client Proxies.

Enable API Versioning

Install Asp.Versioning.Mvc.ApiExplorer from nuget package resource

<Project Sdk="Microsoft.NET.Sdk.Web">
  <ItemGroup>
    <PackageReference Include="Asp.Versioning.Mvc.ApiExplorer" Version="8.1.0" />
  </ItemGroup>
</Project>

Use AddApiVersioning extensions and AbpAspNetCoreMvcOptions options class to register the api versioning in the ConfigureServices method of your module.

public override void ConfigureServices(ServiceConfigurationContext context)
{
    // https://github.com/dotnet/aspnet-api-versioning/issues/1029
    context.Services.AddTransient<IApiControllerFilter, NoControllerFilter>();
    context.Services.AddApiVersioning(options =>
    {
      options.AssumeDefaultVersionWhenUnspecified = true;
      options.ReportApiVersions = true;
    })
    .AddMvc()
    .AddApiExplorer(options =>
    {
      // The specified format code will format the version as "'v'major[.minor][-status]
      options.GroupNameFormat = "'v'VVV";
      // Note : this option is only necessary when versioning by url segment. the SubstitutionFormat
      // Can also be used to control the format of the API version in route templates
      options.SubstituteApiVersionInUrl = true;
    });

    Configure<AbpAspNetCoreMvcOptions>(options =>
    {
      options.ChangeControllerModelApiExplorerGroupName = false;
    });
}