Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

API Version Selector

Chris Martinez edited this pageJul 5, 2023 ·6 revisions

TheIApiVersionSelector interface defines the behavior of how an API version is selected for a given request context. This service is typically only used when a client has not requested an explicit API version and theAssumeDefaultVersionWhenUnspecified option is enabled. The role of the API version selector is to select the appropriate API version given the current request and a model of available API versions.

Although theIApiVersionSelectorcan be used for other scenarios, it is currently only utilized when no API version is requested by a client and the server allows this behavior. The selector provides the rules thatselect the most appropriate API version according to the server. There is no built-in capability to ignore an API version explicitly requested by a client.

There are four API version selectors provided out-of-the-box or you can implement your own. The default, configured API version selector isDefaultApiVersionSelector.

ASP.NET Web API

publicinterfaceIApiVersionSelector{ApiVersionSelectVersion(HttpRequestMessagerequest,ApiVersionModelmodel);}

ASP.NET Core

publicinterfaceIApiVersionSelector{ApiVersion?SelectVersion(HttpRequestrequest,ApiVersionModelmodel);}

Default API Version Selector

TheDefaultApiVersionSelector always selects the configuredDefaultApiVersion, regardless of the request or available API version information.

Constant API Version Selector

TheConstantApiVersionSelector always selects a user-defined API version, regardless of the request or available API version information.

services.AddApiVersioning(    options=>options.ApiVersionSelector=newConstantApiVersionSelector(newApiVersion(new(2016,7,1)));

Current Implementation API Selector

TheCurrentImplementationApiVersionSelector selects the maximum API version available which does not have a version status. If no match is found, it falls back to the configuredDefaultApiVersion. For example, if the versions1.0,2.0, and3.0-alpha are available, then2.0 will be selected because it's the highest, implemented or released API version.

services.AddApiVersioning(    options=>options.ApiVersionSelector=newCurrentImplementationApiVersionSelector(options));

Lowest Implemented API Selector

TheLowestImplementedApiVersionSelector selects the minimum API version available which does not have a version status. If no match is found, it falls back to the configuredDefaultApiVersion. For example, if the versions "0.9-Beta", "1.0", "2.0", and "3.0-Alpha" are available, then "1.0" will be selected because it’s the lowest, implemented or released API version. Your services must be decorated with one or more API versions for the selector to work effectively or it will always select the configuredDefaultApiVersion.

services.AddApiVersioning(    options=>options.ApiVersionSelector=newLowestImplementedApiVersionSelector(options));
Clone this wiki locally

[8]ページ先頭

©2009-2025 Movatter.jp