@@ -5,13 +5,11 @@ namespace Microsoft.Extensions.DependencyInjection;
5
5
using Asp . Versioning ;
6
6
using Asp . Versioning . ApiExplorer ;
7
7
using Microsoft . AspNetCore . Builder ;
8
- using Microsoft . AspNetCore . Http ;
9
8
using Microsoft . AspNetCore . Mvc . ApiExplorer ;
10
9
using Microsoft . AspNetCore . Mvc . ModelBinding ;
11
10
using Microsoft . AspNetCore . Routing ;
12
11
using Microsoft . Extensions . DependencyInjection . Extensions ;
13
12
using Microsoft . Extensions . Options ;
14
- using Microsoft . Extensions . Primitives ;
15
13
using static ServiceDescriptor ;
16
14
17
15
/// <summary>
@@ -54,54 +52,17 @@ private static void AddApiExplorerServices( IApiVersioningBuilder builder )
54
52
55
53
services . AddMvcCore ( ) . AddApiExplorer ( ) ;
56
54
services . TryAddSingleton < IOptionsFactory < ApiExplorerOptions > , ApiExplorerOptionsFactory < ApiExplorerOptions > > ( ) ;
57
- services . TryAddTransient ( ResolveApiVersionDescriptionProviderFactory ) ;
58
- services . TryAddSingleton ( ResolveApiVersionDescriptionProvider ) ;
55
+ services . TryAddTransient < IApiVersionDescriptionProviderFactory , ApiVersionDescriptionProviderFactory > ( ) ;
56
+ services . TryAddSingleton ( static sp => sp . GetRequiredService < IApiVersionDescriptionProviderFactory > ( ) . Create ( ) ) ;
59
57
60
58
// use internal constructor until ASP.NET Core fixes their bug
61
59
// BUG: https://github.com/dotnet/aspnetcore/issues/41773
62
60
services . TryAddEnumerable (
63
61
Transient < IApiDescriptionProvider , VersionedApiDescriptionProvider > (
64
- sp => new (
62
+ static sp => new (
65
63
sp . GetRequiredService < ISunsetPolicyManager > ( ) ,
66
64
sp . GetRequiredService < IModelMetadataProvider > ( ) ,
67
65
sp . GetRequiredService < IInlineConstraintResolver > ( ) ,
68
66
sp . GetRequiredService < IOptions < ApiExplorerOptions > > ( ) ) ) ) ;
69
67
}
70
-
71
- private static IApiVersionDescriptionProviderFactory ResolveApiVersionDescriptionProviderFactory ( IServiceProvider serviceProvider )
72
- {
73
- var sunsetPolicyManager = serviceProvider . GetRequiredService < ISunsetPolicyManager > ( ) ;
74
- var providers = serviceProvider . GetServices < IApiVersionMetadataCollationProvider > ( ) ;
75
- var inspector = serviceProvider . GetRequiredService < IEndpointInspector > ( ) ;
76
- var options = serviceProvider . GetRequiredService < IOptions < ApiExplorerOptions > > ( ) ;
77
-
78
- return new ApiVersionDescriptionProviderFactory (
79
- NewDefaultProvider ,
80
- sunsetPolicyManager ,
81
- providers ,
82
- inspector ,
83
- options ) ;
84
-
85
- static DefaultApiVersionDescriptionProvider NewDefaultProvider (
86
- IEnumerable < IApiVersionMetadataCollationProvider > providers ,
87
- ISunsetPolicyManager sunsetPolicyManager ,
88
- IOptions < ApiExplorerOptions > apiExplorerOptions ) =>
89
- new ( providers , sunsetPolicyManager , apiExplorerOptions ) ;
90
- }
91
-
92
- private static IApiVersionDescriptionProvider ResolveApiVersionDescriptionProvider ( IServiceProvider serviceProvider )
93
- {
94
- var factory = serviceProvider . GetRequiredService < IApiVersionDescriptionProviderFactory > ( ) ;
95
- var endpointDataSource = new EmptyEndpointDataSource ( ) ;
96
- return factory . Create ( endpointDataSource ) ;
97
- }
98
-
99
- private sealed class EmptyEndpointDataSource : EndpointDataSource
100
- {
101
- public override IReadOnlyList < Endpoint > Endpoints => Array . Empty < Endpoint > ( ) ;
102
-
103
- public override IChangeToken GetChangeToken ( ) => new CancellationChangeToken ( CancellationToken . None ) ;
104
-
105
- public override IReadOnlyList < Endpoint > GetGroupedEndpoints ( RouteGroupContext context ) => Array . Empty < Endpoint > ( ) ;
106
- }
107
68
}
0 commit comments