-
Notifications
You must be signed in to change notification settings - Fork 697
/
ApiVersioningFeature.cs
63 lines (55 loc) · 1.92 KB
/
ApiVersioningFeature.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
namespace Microsoft.AspNetCore.Mvc.Versioning
{
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.DependencyInjection;
using System;
/// <summary>
/// Represents the API versioning feature.
/// </summary>
[CLSCompliant( false )]
public sealed class ApiVersioningFeature : IApiVersioningFeature
{
readonly HttpContext context;
string? rawApiVersion;
ApiVersion? apiVersion;
/// <summary>
/// Initializes a new instance of the <see cref="ApiVersioningFeature"/> class.
/// </summary>
/// <param name="context">The current <see cref="HttpContext">HTTP context</see>.</param>
[CLSCompliant( false )]
public ApiVersioningFeature( HttpContext context ) => this.context = context;
/// <inheritdoc />
public string? RouteParameter { get; set; }
/// <inheritdoc />
public string? RawRequestedApiVersion
{
get
{
if ( rawApiVersion == null )
{
var reader = context.RequestServices.GetService<IApiVersionReader>() ?? new QueryStringApiVersionReader();
rawApiVersion = reader.Read( context.Request );
}
return rawApiVersion;
}
set => rawApiVersion = value;
}
/// <inheritdoc />
public ApiVersion? RequestedApiVersion
{
get
{
if ( apiVersion == null )
{
#pragma warning disable CA1806 // Do not ignore method results
ApiVersion.TryParse( RawRequestedApiVersion, out apiVersion );
#pragma warning restore CA1806
}
return apiVersion;
}
set => apiVersion = value;
}
/// <inheritdoc />
public ActionSelectionResult SelectionResult { get; } = new ActionSelectionResult();
}
}