Table of Contents

RestfulApiVersioningOptions Class

Definition

Namespace
Codebelt.Extensions.Asp.Versioning
Assemblies
Codebelt.Extensions.Asp.Versioning.dll
Source
src/Codebelt.Extensions.Asp.Versioning/RestfulApiVersioningOptions.cs
public class RestfulApiVersioningOptions : IValidatableParameterObject, IParameterObject
Inheritance
RestfulApiVersioningOptions
Implements

Examples

Inspect or adjust the defaults applied by AddRestfulApiVersioning by constructing a RestfulApiVersioningOptions instance directly. Defaults include API version 1.0, the parameter name "v", a broad set of accepted media types, CurrentImplementationApiVersionSelector, and custom RFC 7807 problem-details handling. The example below trims the accepted media-type list to JSON only and switches the version selector to always route to the lowest implemented version.

using System.Collections.Generic;
using Asp.Versioning;
using Codebelt.Extensions.Asp.Versioning;

namespace Codebelt.Extensions.Asp.Versioning;

public class VersioningOptionsSetup
{
    public static RestfulApiVersioningOptions CreateOptions()
    {
        var options = new RestfulApiVersioningOptions
        {
            DefaultApiVersion = new ApiVersion(1, 0),
            ParameterName = "v",
            ReportApiVersions = true,
            ValidAcceptHeaders = new List<string>
            {
                "application/json",
                "text/json"
            }
        };
        options.UseApiVersionSelector<LowestImplementedApiVersionSelector>();
        return options;
    }
}

Constructors

Name Description
RestfulApiVersioningOptions()

Initializes a new instance of the RestfulApiVersioningOptions class.

Properties

Name Description
ApiVersionReader

Gets or sets the API version reader used to read the API version from the request.

ApiVersionSelectorType

Gets the concrete implementation type of a type that implements the Asp.Versioning.IApiVersionSelector interface.

Conventions

Gets or sets the builder used to define API version conventions.

DefaultApiVersion

Gets or sets 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.

ReportApiVersions

Gets or sets a value indicating whether requests report the API version compatibility information in responses.

UseBuiltInRfc7807

Gets or sets a value indicating whether responses will be based on the built in support for RFC 7807.

ValidAcceptHeaders

Gets or sets the valid accept headers used as a filter by RestfulApiVersionReader.

Methods

Name Description
UseApiVersionSelector<T>()

Specify what Asp.Versioning.IApiVersionSelector to set on the ApiVersionSelectorType. Default is Asp.Versioning.CurrentImplementationApiVersionSelector.

ValidateOptions()

Determines whether the public read-write properties of this instance are in a valid state.