Table of Contents

UseRestfulApiVersioning Method

Definition

Namespace
Codebelt.Extensions.Asp.Versioning
Assemblies
Codebelt.Extensions.Asp.Versioning.dll
Source
src/Codebelt.Extensions.Asp.Versioning/ApplicationBuilderExtensions.cs

UseRestfulApiVersioning(IApplicationBuilder, Func<HttpContext, HttpStatusCodeException>)

Adds a middleware to the pipeline that will intercept status codes written directly to the response and throw an appropriate HttpStatusCodeException that can then be translated and re-written in a consistent way.

public static IApplicationBuilder UseRestfulApiVersioning(this IApplicationBuilder builder, Func<HttpContext, HttpStatusCodeException> statusCodeExceptionFactory = null)

Parameters

builder IApplicationBuilder

The type that provides the mechanisms to configure an application’s request pipeline.

statusCodeExceptionFactory Func<HttpContext, HttpStatusCodeException>

The function delegate that will resolve and throw a proper HttpStatusCodeException from status codes written directly to the response.

Returns

IApplicationBuilder

A reference to this instance after the operation has completed.

Remarks

This method was introduced because of the design decisions made of the author of Asp.Versioning; for more information have a read at https://github.com/dotnet/aspnet-api-versioning/issues/886

Exceptions

ArgumentNullException

builder cannot be null.