Skip to content

Commit 9483768

Browse files
committed
PR feedback
1 parent bf19e03 commit 9483768

File tree

4 files changed

+23
-7
lines changed

4 files changed

+23
-7
lines changed

src/Http/Http.Abstractions/src/Extensions/EndpointBuilder.cs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// Licensed to the .NET Foundation under one or more agreements.
22
// The .NET Foundation licenses this file to you under the MIT license.
33

4+
using System.Diagnostics.CodeAnalysis;
45
using Microsoft.AspNetCore.Http;
56

67
namespace Microsoft.AspNetCore.Builder;
@@ -15,7 +16,14 @@ public abstract class EndpointBuilder
1516
/// <summary>
1617
/// Gets the list of filters that apply to this endpoint.
1718
/// </summary>
18-
public IList<Func<EndpointFilterFactoryContext, EndpointFilterDelegate, EndpointFilterDelegate>> FilterFactories => _filterFactories ??= new();
19+
public IList<Func<EndpointFilterFactoryContext, EndpointFilterDelegate, EndpointFilterDelegate>> FilterFactories
20+
{
21+
[RequiresDynamicCode("Filter factories generate dynamic code and aren't compatible with native AOT applications.")]
22+
get
23+
{
24+
return _filterFactories ??= new();
25+
}
26+
}
1927

2028
/// <summary>
2129
/// Gets or sets the delegate used to process requests for the endpoint.

src/Http/Http.Extensions/src/RequestDelegateFactory.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,7 @@ private static RequestDelegateFactoryContext CreateFactoryContext(RequestDelegat
262262
}
263263

264264
var serviceProvider = options?.ServiceProvider ?? options?.EndpointBuilder?.ApplicationServices ?? EmptyServiceProvider.Instance;
265-
var endpointBuilder = options?.EndpointBuilder ?? new RDFEndpointBuilder(serviceProvider);
265+
var endpointBuilder = options?.EndpointBuilder ?? new RdfEndpointBuilder(serviceProvider);
266266
var jsonSerializerOptions = serviceProvider.GetService<IOptions<JsonOptions>>()?.Value.SerializerOptions;
267267

268268
var factoryContext = new RequestDelegateFactoryContext
@@ -2525,9 +2525,9 @@ public Task ExecuteAsync(HttpContext httpContext)
25252525
}
25262526
}
25272527

2528-
private sealed class RDFEndpointBuilder : EndpointBuilder
2528+
private sealed class RdfEndpointBuilder : EndpointBuilder
25292529
{
2530-
public RDFEndpointBuilder(IServiceProvider applicationServices)
2530+
public RdfEndpointBuilder(IServiceProvider applicationServices)
25312531
{
25322532
ApplicationServices = applicationServices;
25332533
}

src/Http/Routing/src/Builder/EndpointFilterExtensions.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,15 @@ namespace Microsoft.AspNetCore.Http;
1313
/// </summary>
1414
public static class EndpointFilterExtensions
1515
{
16+
internal const string FilterRequiresDynamicCodeWarning = "Filter factories generate dynamic code and aren't compatible with native AOT applications.";
17+
1618
/// <summary>
1719
/// Registers a filter onto the route handler.
1820
/// </summary>
1921
/// <param name="builder">The <see cref="RouteHandlerBuilder"/>.</param>
2022
/// <param name="filter">The <see cref="IEndpointFilter"/> to register.</param>
2123
/// <returns>A <see cref="RouteHandlerBuilder"/> that can be used to further customize the route handler.</returns>
24+
[RequiresDynamicCode(FilterRequiresDynamicCodeWarning)]
2225
public static TBuilder AddEndpointFilter<TBuilder>(this TBuilder builder, IEndpointFilter filter) where TBuilder : IEndpointConventionBuilder =>
2326
builder.AddEndpointFilterFactory((routeHandlerContext, next) => (context) => filter.InvokeAsync(context, next));
2427

@@ -29,6 +32,7 @@ public static TBuilder AddEndpointFilter<TBuilder>(this TBuilder builder, IEndpo
2932
/// <typeparam name="TFilterType">The type of the <see cref="IEndpointFilter"/> to register.</typeparam>
3033
/// <param name="builder">The <see cref="RouteHandlerBuilder"/>.</param>
3134
/// <returns>A <see cref="RouteHandlerBuilder"/> that can be used to further customize the route handler.</returns>
35+
[RequiresDynamicCode(FilterRequiresDynamicCodeWarning)]
3236
public static TBuilder AddEndpointFilter<TBuilder, [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors)] TFilterType>(this TBuilder builder)
3337
where TBuilder : IEndpointConventionBuilder
3438
where TFilterType : IEndpointFilter
@@ -63,6 +67,7 @@ public static TBuilder AddEndpointFilter<TBuilder>(this TBuilder builder, IEndpo
6367
/// <typeparam name="TFilterType">The type of the <see cref="IEndpointFilter"/> to register.</typeparam>
6468
/// <param name="builder">The <see cref="RouteHandlerBuilder"/>.</param>
6569
/// <returns>A <see cref="RouteHandlerBuilder"/> that can be used to further customize the route handler.</returns>
70+
[RequiresDynamicCode(FilterRequiresDynamicCodeWarning)]
6671
public static RouteHandlerBuilder AddEndpointFilter<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors)] TFilterType>(this RouteHandlerBuilder builder)
6772
where TFilterType : IEndpointFilter
6873
{
@@ -76,6 +81,7 @@ public static TBuilder AddEndpointFilter<TBuilder>(this TBuilder builder, IEndpo
7681
/// <typeparam name="TFilterType">The type of the <see cref="IEndpointFilter"/> to register.</typeparam>
7782
/// <param name="builder">The <see cref="RouteHandlerBuilder"/>.</param>
7883
/// <returns>A <see cref="RouteHandlerBuilder"/> that can be used to further customize the route handler.</returns>
84+
[RequiresDynamicCode(FilterRequiresDynamicCodeWarning)]
7985
public static RouteGroupBuilder AddEndpointFilter<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors)] TFilterType>(this RouteGroupBuilder builder)
8086
where TFilterType : IEndpointFilter
8187
{
@@ -89,6 +95,7 @@ public static TBuilder AddEndpointFilter<TBuilder>(this TBuilder builder, IEndpo
8995
/// <param name="builder">The <see cref="RouteHandlerBuilder"/>.</param>
9096
/// <param name="routeHandlerFilter">A method representing the core logic of the filter.</param>
9197
/// <returns>A <see cref="RouteHandlerBuilder"/> that can be used to further customize the route handler.</returns>
98+
[RequiresDynamicCode(FilterRequiresDynamicCodeWarning)]
9299
public static TBuilder AddEndpointFilter<TBuilder>(this TBuilder builder, Func<EndpointFilterInvocationContext, EndpointFilterDelegate, ValueTask<object?>> routeHandlerFilter)
93100
where TBuilder : IEndpointConventionBuilder
94101
{
@@ -101,6 +108,7 @@ public static TBuilder AddEndpointFilter<TBuilder>(this TBuilder builder, Func<E
101108
/// <param name="builder">The <see cref="RouteHandlerBuilder"/>.</param>
102109
/// <param name="filterFactory">A method representing the logic for constructing the filter.</param>
103110
/// <returns>A <see cref="RouteHandlerBuilder"/> that can be used to further customize the route handler.</returns>
111+
[RequiresDynamicCode(FilterRequiresDynamicCodeWarning)]
104112
public static TBuilder AddEndpointFilterFactory<TBuilder>(this TBuilder builder, Func<EndpointFilterFactoryContext, EndpointFilterDelegate, EndpointFilterDelegate> filterFactory)
105113
where TBuilder : IEndpointConventionBuilder
106114
{

src/Http/Routing/src/RouteEndpointDataSource.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ private RouteEndpointBuilder CreateRouteEndpointBuilder(
202202
// they can do so via IEndpointConventionBuilder.Finally like the do to override any other entry-specific metadata.
203203
if (isRouteHandler)
204204
{
205-
rdfOptions = CreateRDFOptions(entry, pattern, builder);
205+
rdfOptions = CreateRdfOptions(entry, pattern, builder);
206206
rdfMetadataResult = RequestDelegateFactory.InferMetadata(entry.RouteHandler.Method, rdfOptions);
207207
}
208208

@@ -227,7 +227,7 @@ private RouteEndpointBuilder CreateRouteEndpointBuilder(
227227

228228
if (isRouteHandler || builder.FilterFactories.Count > 0)
229229
{
230-
rdfOptions ??= CreateRDFOptions(entry, pattern, builder);
230+
rdfOptions ??= CreateRdfOptions(entry, pattern, builder);
231231

232232
// We ignore the returned EndpointMetadata has been already populated since we passed in non-null EndpointMetadata.
233233
// We always set factoryRequestDelegate in case something is still referencing the redirected version of the RequestDelegate.
@@ -259,7 +259,7 @@ private RouteEndpointBuilder CreateRouteEndpointBuilder(
259259
return builder;
260260
}
261261

262-
private RequestDelegateFactoryOptions CreateRDFOptions(RouteEntry entry, RoutePattern pattern, RouteEndpointBuilder builder)
262+
private RequestDelegateFactoryOptions CreateRdfOptions(RouteEntry entry, RoutePattern pattern, RouteEndpointBuilder builder)
263263
{
264264
var routeParamNames = new List<string>(pattern.Parameters.Count);
265265
foreach (var parameter in pattern.Parameters)

0 commit comments

Comments
 (0)