@@ -137,7 +137,8 @@ internal WebApplicationBuilder(WebApplicationOptions options, bool slim, Action<
137
137
{
138
138
AspNetCore . WebHost . ConfigureWebDefaultsCore ( webHostBuilder ) ;
139
139
140
- webHostBuilder . Configure ( ConfigureEmptyApplication ) ;
140
+ // Runs inline.
141
+ webHostBuilder . Configure ( ConfigureApplication ) ;
141
142
142
143
webHostBuilder . UseSetting ( WebHostDefaults . ApplicationKey , _hostApplicationBuilder . Environment . ApplicationName ?? "" ) ;
143
144
webHostBuilder . UseSetting ( WebHostDefaults . PreventHostingStartupKey , Configuration [ WebHostDefaults . PreventHostingStartupKey ] ) ;
@@ -260,46 +261,6 @@ public WebApplication Build()
260
261
}
261
262
262
263
private void ConfigureApplication ( WebHostBuilderContext context , IApplicationBuilder app )
263
- {
264
- ConfigureApplicationCore (
265
- context ,
266
- app ,
267
- processAuthMiddlewares : ( ) =>
268
- {
269
- Debug . Assert ( _builtApplication is not null ) ;
270
-
271
- // Process authorization and authentication middlewares independently to avoid
272
- // registering middlewares for services that do not exist
273
- var serviceProviderIsService = _builtApplication . Services . GetService < IServiceProviderIsService > ( ) ;
274
- if ( serviceProviderIsService ? . IsService ( typeof ( IAuthenticationSchemeProvider ) ) is true )
275
- {
276
- // Don't add more than one instance of the middleware
277
- if ( ! _builtApplication . Properties . ContainsKey ( AuthenticationMiddlewareSetKey ) )
278
- {
279
- // The Use invocations will set the property on the outer pipeline,
280
- // but we want to set it on the inner pipeline as well.
281
- _builtApplication . Properties [ AuthenticationMiddlewareSetKey ] = true ;
282
- app . UseAuthentication ( ) ;
283
- }
284
- }
285
-
286
- if ( serviceProviderIsService ? . IsService ( typeof ( IAuthorizationHandlerProvider ) ) is true )
287
- {
288
- if ( ! _builtApplication . Properties . ContainsKey ( AuthorizationMiddlewareSetKey ) )
289
- {
290
- _builtApplication . Properties [ AuthorizationMiddlewareSetKey ] = true ;
291
- app . UseAuthorization ( ) ;
292
- }
293
- }
294
- } ) ;
295
- }
296
-
297
- private void ConfigureEmptyApplication ( WebHostBuilderContext context , IApplicationBuilder app )
298
- {
299
- ConfigureApplicationCore ( context , app , processAuthMiddlewares : null ) ;
300
- }
301
-
302
- private void ConfigureApplicationCore ( WebHostBuilderContext context , IApplicationBuilder app , Action ? processAuthMiddlewares )
303
264
{
304
265
Debug . Assert ( _builtApplication is not null ) ;
305
266
@@ -340,7 +301,29 @@ private void ConfigureApplicationCore(WebHostBuilderContext context, IApplicatio
340
301
}
341
302
}
342
303
343
- processAuthMiddlewares ? . Invoke ( ) ;
304
+ // Process authorization and authentication middlewares independently to avoid
305
+ // registering middlewares for services that do not exist
306
+ var serviceProviderIsService = _builtApplication . Services . GetService < IServiceProviderIsService > ( ) ;
307
+ if ( serviceProviderIsService ? . IsService ( typeof ( IAuthenticationSchemeProvider ) ) is true )
308
+ {
309
+ // Don't add more than one instance of the middleware
310
+ if ( ! _builtApplication . Properties . ContainsKey ( AuthenticationMiddlewareSetKey ) )
311
+ {
312
+ // The Use invocations will set the property on the outer pipeline,
313
+ // but we want to set it on the inner pipeline as well.
314
+ _builtApplication . Properties [ AuthenticationMiddlewareSetKey ] = true ;
315
+ app . UseAuthentication ( ) ;
316
+ }
317
+ }
318
+
319
+ if ( serviceProviderIsService ? . IsService ( typeof ( IAuthorizationHandlerProvider ) ) is true )
320
+ {
321
+ if ( ! _builtApplication . Properties . ContainsKey ( AuthorizationMiddlewareSetKey ) )
322
+ {
323
+ _builtApplication . Properties [ AuthorizationMiddlewareSetKey ] = true ;
324
+ app . UseAuthorization ( ) ;
325
+ }
326
+ }
344
327
345
328
// Wire the source pipeline to run in the destination pipeline
346
329
app . Use ( next =>
0 commit comments