2
2
// The .NET Foundation licenses this file to you under the MIT license.
3
3
4
4
using System . Diagnostics ;
5
- using System . Diagnostics . CodeAnalysis ;
6
5
using System . Reflection ;
7
6
using System . Runtime . CompilerServices ;
8
7
using Microsoft . AspNetCore . Builder ;
@@ -28,7 +27,8 @@ public RouteEndpointDataSource(IServiceProvider applicationServices, bool throwO
28
27
public RouteHandlerBuilder AddRequestDelegate (
29
28
RoutePattern pattern ,
30
29
RequestDelegate requestDelegate ,
31
- IEnumerable < string > ? httpMethods )
30
+ IEnumerable < string > ? httpMethods ,
31
+ Func < Delegate , RequestDelegateFactoryOptions , RequestDelegateMetadataResult ? , RequestDelegateResult > createHandlerRequestDelegateFunc )
32
32
{
33
33
var conventions = new ThrowOnAddAfterEndpointBuiltConventionCollection ( ) ;
34
34
var finallyConventions = new ThrowOnAddAfterEndpointBuiltConventionCollection ( ) ;
@@ -42,30 +42,19 @@ public RouteHandlerBuilder AddRequestDelegate(
42
42
Conventions = conventions ,
43
43
FinallyConventions = finallyConventions ,
44
44
InferMetadataFunc = null , // Metadata isn't infered from RequestDelegate endpoints
45
- CreateHandlerRequestDelegateFunc = CreateHandlerRequestDelegate
45
+ CreateHandlerRequestDelegateFunc = createHandlerRequestDelegateFunc
46
46
} ) ;
47
47
48
48
return new RouteHandlerBuilder ( conventions , finallyConventions ) ;
49
-
50
- static RequestDelegate CreateHandlerRequestDelegate ( Delegate handler , RequestDelegateFactoryOptions options , RequestDelegateMetadataResult ? metadataResult )
51
- {
52
- var requestDelegate = ( RequestDelegate ) handler ;
53
-
54
- // Use request delegate directly when there are no filters.
55
- if ( options . EndpointBuilder is null || options . EndpointBuilder . FilterFactories . Count == 0 )
56
- {
57
- return requestDelegate ;
58
- }
59
-
60
- return RequestDelegateFilterPipelineBuilder . Create ( requestDelegate , options ) ;
61
- }
62
49
}
63
50
64
51
public RouteHandlerBuilder AddRouteHandler (
65
52
RoutePattern pattern ,
66
53
Delegate routeHandler ,
67
54
IEnumerable < string > ? httpMethods ,
68
- bool isFallback )
55
+ bool isFallback ,
56
+ Func < MethodInfo , RequestDelegateFactoryOptions ? , RequestDelegateMetadataResult > ? inferMetadataFunc ,
57
+ Func < Delegate , RequestDelegateFactoryOptions , RequestDelegateMetadataResult ? , RequestDelegateResult > createHandlerRequestDelegateFunc )
69
58
{
70
59
var conventions = new ThrowOnAddAfterEndpointBuiltConventionCollection ( ) ;
71
60
var finallyConventions = new ThrowOnAddAfterEndpointBuiltConventionCollection ( ) ;
@@ -84,33 +73,11 @@ public RouteHandlerBuilder AddRouteHandler(
84
73
RouteAttributes = routeAttributes ,
85
74
Conventions = conventions ,
86
75
FinallyConventions = finallyConventions ,
87
- InferMetadataFunc = InferHandlerMetadata ,
88
- CreateHandlerRequestDelegateFunc = CreateHandlerRequestDelegate
76
+ InferMetadataFunc = inferMetadataFunc ,
77
+ CreateHandlerRequestDelegateFunc = createHandlerRequestDelegateFunc
89
78
} ) ;
90
79
91
80
return new RouteHandlerBuilder ( conventions , finallyConventions ) ;
92
-
93
- [ UnconditionalSuppressMessage ( "Trimmer" , "IL2026" ,
94
- Justification = "We surface a RequireUnreferencedCode in the call to the Map methods adding route handlers to this EndpointDataSource. Analysis is unable to infer this. " +
95
- "Map methods that configure a RequestDelegate don't use trimmer unsafe features." ) ]
96
- [ UnconditionalSuppressMessage ( "AOT" , "IL3050" ,
97
- Justification = "We surface a RequiresDynamicCode in the call to the Map methods adding route handlers this EndpointDataSource. Analysis is unable to infer this. " +
98
- "Map methods that configure a RequestDelegate don't use AOT unsafe features." ) ]
99
- static RequestDelegateMetadataResult InferHandlerMetadata ( MethodInfo methodInfo , RequestDelegateFactoryOptions ? options = null )
100
- {
101
- return RequestDelegateFactory . InferMetadata ( methodInfo , options ) ;
102
- }
103
-
104
- [ UnconditionalSuppressMessage ( "Trimmer" , "IL2026" ,
105
- Justification = "We surface a RequireUnreferencedCode in the call to the Map methods adding route handlers to this EndpointDataSource. Analysis is unable to infer this. " +
106
- "Map methods that configure a RequestDelegate don't use trimmer unsafe features." ) ]
107
- [ UnconditionalSuppressMessage ( "AOT" , "IL3050" ,
108
- Justification = "We surface a RequiresDynamicCode in the call to the Map methods adding route handlers this EndpointDataSource. Analysis is unable to infer this. " +
109
- "Map methods that configure a RequestDelegate don't use AOT unsafe features." ) ]
110
- static RequestDelegate CreateHandlerRequestDelegate ( Delegate handler , RequestDelegateFactoryOptions options , RequestDelegateMetadataResult ? metadataResult )
111
- {
112
- return RequestDelegateFactory . Create ( handler , options , metadataResult ) . RequestDelegate ;
113
- }
114
81
}
115
82
116
83
public override IReadOnlyList < RouteEndpoint > Endpoints
@@ -265,7 +232,7 @@ private RouteEndpointBuilder CreateRouteEndpointBuilder(
265
232
266
233
// We ignore the returned EndpointMetadata has been already populated since we passed in non-null EndpointMetadata.
267
234
// We always set factoryRequestDelegate in case something is still referencing the redirected version of the RequestDelegate.
268
- factoryCreatedRequestDelegate = entry . CreateHandlerRequestDelegateFunc ( entry . RouteHandler , rdfOptions , rdfMetadataResult ) ;
235
+ factoryCreatedRequestDelegate = entry . CreateHandlerRequestDelegateFunc ( entry . RouteHandler , rdfOptions , rdfMetadataResult ) . RequestDelegate ;
269
236
}
270
237
271
238
Debug . Assert ( factoryCreatedRequestDelegate is not null ) ;
@@ -350,7 +317,7 @@ private readonly struct RouteEntry
350
317
public required ThrowOnAddAfterEndpointBuiltConventionCollection Conventions { get ; init ; }
351
318
public required ThrowOnAddAfterEndpointBuiltConventionCollection FinallyConventions { get ; init ; }
352
319
public required Func < MethodInfo , RequestDelegateFactoryOptions ? , RequestDelegateMetadataResult > ? InferMetadataFunc { get ; init ; }
353
- public required Func < Delegate , RequestDelegateFactoryOptions , RequestDelegateMetadataResult ? , RequestDelegate > CreateHandlerRequestDelegateFunc { get ; init ; }
320
+ public required Func < Delegate , RequestDelegateFactoryOptions , RequestDelegateMetadataResult ? , RequestDelegateResult > CreateHandlerRequestDelegateFunc { get ; init ; }
354
321
}
355
322
356
323
[ Flags ]
0 commit comments