@@ -9,7 +9,6 @@ namespace Microsoft.Extensions.DependencyInjection;
9
9
using Microsoft . AspNetCore . Http ;
10
10
using Microsoft . AspNetCore . Http . Features ;
11
11
using Microsoft . AspNetCore . Mvc . ApplicationModels ;
12
- using Microsoft . AspNetCore . Mvc . ApplicationParts ;
13
12
using Microsoft . AspNetCore . OData ;
14
13
using Microsoft . AspNetCore . OData . Routing . Template ;
15
14
using Microsoft . AspNetCore . Routing ;
@@ -66,8 +65,7 @@ private static void AddServices( IServiceCollection services )
66
65
services . TryRemoveODataService ( typeof ( IApplicationModelProvider ) , ODataRoutingApplicationModelProviderType ) ;
67
66
68
67
var partManager = services . GetOrCreateApplicationPartManager ( ) ;
69
-
70
- ConfigureDefaultFeatureProviders ( partManager ) ;
68
+ var configured = partManager . ConfigureDefaultFeatureProviders ( ) ;
71
69
72
70
services . AddHttpContextAccessor ( ) ;
73
71
services . TryAddSingleton < VersionedODataOptions > ( ) ;
@@ -84,24 +82,11 @@ private static void AddServices( IServiceCollection services )
84
82
services . TryAddEnumerable ( Singleton < MatcherPolicy , DefaultMetadataMatcherPolicy > ( ) ) ;
85
83
services . TryAddEnumerable ( Transient < IApplicationModelProvider , ODataApplicationModelProvider > ( ) ) ;
86
84
services . TryAddEnumerable ( Transient < IApplicationModelProvider , ODataMultiModelApplicationModelProvider > ( ) ) ;
87
- services . AddModelConfigurationsAsServices ( partManager ) ;
88
- }
89
-
90
- private static T GetService < T > ( this IServiceCollection services ) =>
91
- ( T ) services . LastOrDefault ( d => d . ServiceType == typeof ( T ) ) ? . ImplementationInstance ! ;
92
-
93
- private static ApplicationPartManager GetOrCreateApplicationPartManager ( this IServiceCollection services )
94
- {
95
- var partManager = services . GetService < ApplicationPartManager > ( ) ;
96
85
97
- if ( partManager == null )
86
+ if ( configured )
98
87
{
99
- partManager = new ApplicationPartManager ( ) ;
100
- services . TryAddSingleton ( partManager ) ;
88
+ services . AddModelConfigurationsAsServices ( partManager ) ;
101
89
}
102
-
103
- partManager . ApplicationParts . Add ( new AssemblyPart ( typeof ( ODataApiVersioningOptions ) . Assembly ) ) ;
104
- return partManager ;
105
90
}
106
91
107
92
[ MethodImpl ( MethodImplOptions . AggressiveInlining ) ]
@@ -148,27 +133,6 @@ private static void TryReplaceODataService(
148
133
}
149
134
}
150
135
151
- private static void AddModelConfigurationsAsServices ( this IServiceCollection services , ApplicationPartManager partManager )
152
- {
153
- var feature = new ModelConfigurationFeature ( ) ;
154
- var modelConfigurationType = typeof ( IModelConfiguration ) ;
155
-
156
- partManager . PopulateFeature ( feature ) ;
157
-
158
- foreach ( var modelConfiguration in feature . ModelConfigurations )
159
- {
160
- services . TryAddEnumerable ( Transient ( modelConfigurationType , modelConfiguration ) ) ;
161
- }
162
- }
163
-
164
- private static void ConfigureDefaultFeatureProviders ( ApplicationPartManager partManager )
165
- {
166
- if ( ! partManager . FeatureProviders . OfType < ModelConfigurationFeatureProvider > ( ) . Any ( ) )
167
- {
168
- partManager . FeatureProviders . Add ( new ModelConfigurationFeatureProvider ( ) ) ;
169
- }
170
- }
171
-
172
136
private static object CreateInstance ( this IServiceProvider services , ServiceDescriptor descriptor )
173
137
{
174
138
if ( descriptor . ImplementationInstance != null )
0 commit comments