Class RestfulApiVersioningOptions
- Namespace
- Codebelt.Extensions.Asp.Versioning
- Assembly
- Codebelt.Extensions.Asp.Versioning.dll
Provides programmatic configuration for the AddRestfulApiVersioning(IServiceCollection, Action<RestfulApiVersioningOptions>) method.
public class RestfulApiVersioningOptions : IValidatableParameterObject, IParameterObject
- Inheritance
-
RestfulApiVersioningOptions
- Implements
Constructors
RestfulApiVersioningOptions()
Initializes a new instance of the RestfulApiVersioningOptions class.
public RestfulApiVersioningOptions()
Remarks
The following table shows the initial property values for an instance of RestfulApiVersioningOptions.
Property | Initial Value |
---|---|
ApiVersionSelectorType | typeof(CurrentImplementationApiVersionSelector) |
Conventions | new ApiVersionConventionBuilder() |
DefaultApiVersion | ApiVersion.Default |
ParameterName | v |
ReportApiVersions | false |
UseBuiltInRfc7807 | false |
ValidAcceptHeaders | application/json, application/xml, application/yaml, application/vnd, text/json, text/xml, text/plain, text/yaml, */* |
Properties
ApiVersionSelectorType
Gets the concrete implementation type of a type that implements the Asp.Versioning.IApiVersionSelector interface.
public Type ApiVersionSelectorType { get; }
Property Value
- Type
The concrete implementation type of a type that implements the Asp.Versioning.IApiVersionSelector interface.
Remarks
Default is Asp.Versioning.CurrentImplementationApiVersionSelector. This can be changed by calling the UseApiVersionSelector<T>().
Conventions
Gets or sets the builder used to define API version conventions.
public IApiVersionConventionBuilder Conventions { get; set; }
Property Value
- IApiVersionConventionBuilder
The builder used to define API version conventions.
DefaultApiVersion
Gets or sets the default API version applied to services that d o not have explicit versions.
public ApiVersion DefaultApiVersion { get; set; }
Property Value
- ApiVersion
The default API version applied to services that do not have explicit versions.
ParameterName
Gets or sets the name of the media type parameter to read the service API version from.
public string ParameterName { get; set; }
Property Value
- String
The name of the media type parameter to read the service API version from.
ReportApiVersions
Gets or sets a value indicating whether requests report the API version compatibility information in responses.
public bool ReportApiVersions { get; set; }
Property Value
- Boolean
true
if the responses contain API version compatibility information; otherwise,false
.
UseBuiltInRfc7807
Gets or sets a value indicating whether responses will be based on the built in support for RFC 7807.
public bool UseBuiltInRfc7807 { get; set; }
Property Value
- Boolean
true
if the responses will be based on the built in support for RFC 7807; otherwise,false
.
ValidAcceptHeaders
Gets or sets the valid accept headers used as a filter by RestfulApiVersionReader.
public IList<string> ValidAcceptHeaders { get; set; }
Property Value
- IList<String>
The valid accept headers used as a filter by RestfulApiVersionReader.
Remarks
This option was introduced to have an inclusive filter on what MIME types to consider valid when parsing HTTP Accept headers; for more information have a read at https://github.com/dotnet/aspnet-api-versioning/issues/887
Methods
UseApiVersionSelector<T>()
Specify what Asp.Versioning.IApiVersionSelector to set on the ApiVersionSelectorType. Default is Asp.Versioning.CurrentImplementationApiVersionSelector.
public RestfulApiVersioningOptions UseApiVersionSelector<T>()
where T : class, IApiVersionSelector
Returns
- RestfulApiVersioningOptions
A reference to this instance so that additional calls can be chained.
Type Parameters
T
The type that implements the Asp.Versioning.IApiVersionSelector interface.
ValidateOptions()
Determines whether the public read-write properties of this instance are in a valid state.
public void ValidateOptions()
Remarks
This method is expected to throw exceptions when one or more conditions fails to be in a valid state.
Exceptions
- InvalidOperationException
ParameterName cannot be null, empty or consist only of white-space characters - or - ValidAcceptHeaders cannot be null.