File tree Expand file tree Collapse file tree 4 files changed +49
-8
lines changed
Asp.Versioning.Mvc.ApiExplorer
Asp.Versioning.WebApi.ApiExplorer/Description Expand file tree Collapse file tree 4 files changed +49
-8
lines changed Original file line number Diff line number Diff line change @@ -255,12 +255,7 @@ private static bool FirstParameterIsOptional(
255255
256256 var mapping = ApiVersionMapping . Explicit | ApiVersionMapping . Implicit ;
257257 var model = apiDescription . ActionDescriptor . GetApiVersionMetadata ( ) . Map ( mapping ) ;
258- ApiVersion defaultApiVersion ;
259-
260- using ( var request = new HttpRequestMessage ( ) )
261- {
262- defaultApiVersion = options . ApiVersionSelector . SelectVersion ( request , model ) ;
263- }
258+ var defaultApiVersion = options . ApiVersionSelector . SelectVersion ( model ) ;
264259
265260 return apiVersion == defaultApiVersion ;
266261 }
Original file line number Diff line number Diff line change 1+ // Copyright (c) .NET Foundation and contributors. All rights reserved.
2+
3+ namespace Asp . Versioning ;
4+
5+ /// <summary>
6+ /// Provides extension methods for <see cref="IApiVersionSelector"/>.
7+ /// </summary>
8+ public static class IApiVersionSelectorExtensions
9+ {
10+ /// <summary>
11+ /// Selects an API version given the specified API version information.
12+ /// </summary>
13+ /// <param name="selector">The extended <see cref="IApiVersionSelector"/>.</param>
14+ /// <param name="model">The <see cref="ApiVersionModel">model</see> to select the version from.</param>
15+ /// <returns>The selected <see cref="ApiVersion">API version</see>.</returns>
16+ public static ApiVersion SelectVersion ( this IApiVersionSelector selector , ApiVersionModel model )
17+ {
18+ ArgumentNullException . ThrowIfNull ( selector ) ;
19+ using var request = new HttpRequestMessage ( ) ;
20+ return selector . SelectVersion ( request , model ) ;
21+ }
22+ }
Original file line number Diff line number Diff line change 1+ // Copyright (c) .NET Foundation and contributors. All rights reserved.
2+
3+ namespace Asp . Versioning ;
4+
5+ using Microsoft . AspNetCore . Http ;
6+
7+ /// <summary>
8+ /// Provides extension methods for <see cref="IApiVersionSelector"/>.
9+ /// </summary>
10+ [ CLSCompliant ( false ) ]
11+ public static class IApiVersionSelectorExtensions
12+ {
13+ /// <summary>
14+ /// Selects an API version given the specified API version information.
15+ /// </summary>
16+ /// <param name="selector">The extended <see cref="IApiVersionSelector"/>.</param>
17+ /// <param name="model">The <see cref="ApiVersionModel">model</see> to select the version from.</param>
18+ /// <returns>The selected <see cref="ApiVersion">API version</see>.</returns>
19+ public static ApiVersion SelectVersion ( this IApiVersionSelector selector , ApiVersionModel model )
20+ {
21+ ArgumentNullException . ThrowIfNull ( selector ) ;
22+ var context = new DefaultHttpContext ( ) ;
23+ return selector . SelectVersion ( context . Request , model ) ;
24+ }
25+ }
Original file line number Diff line number Diff line change @@ -453,8 +453,7 @@ private static bool FirstParameterIsOptional(
453453
454454 var mapping = ApiVersionMapping . Explicit | ApiVersionMapping . Implicit ;
455455 var model = apiDescription . ActionDescriptor . GetApiVersionMetadata ( ) . Map ( mapping ) ;
456- var context = new Microsoft . AspNetCore . Http . DefaultHttpContext ( ) ;
457- var defaultApiVersion = options . ApiVersionSelector . SelectVersion ( context . Request , model ) ;
456+ var defaultApiVersion = options . ApiVersionSelector . SelectVersion ( model ) ;
458457
459458 return apiVersion == defaultApiVersion ;
460459 }
You can’t perform that action at this time.
0 commit comments