Skip to content

Commit 146f49f

Browse files
authored
[Route Groups] Support AddFilter, WithOpenApi and other additive conventions (#42195)
1 parent d4fccce commit 146f49f

38 files changed

+1775
-808
lines changed

src/DefaultBuilder/test/Microsoft.AspNetCore.Tests/WebApplicationTests.cs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1577,12 +1577,13 @@ public async Task BranchingPipelineHasOwnRoutes()
15771577
app.Start();
15781578

15791579
var ds = app.Services.GetRequiredService<EndpointDataSource>();
1580-
Assert.Equal(5, ds.Endpoints.Count);
1581-
Assert.Equal("One", ds.Endpoints[0].DisplayName);
1582-
Assert.Equal("Two", ds.Endpoints[1].DisplayName);
1583-
Assert.Equal("Three", ds.Endpoints[2].DisplayName);
1584-
Assert.Equal("Four", ds.Endpoints[3].DisplayName);
1585-
Assert.Equal("Five", ds.Endpoints[4].DisplayName);
1580+
var displayNames = ds.Endpoints.Select(e => e.DisplayName).ToArray();
1581+
Assert.Equal(5, displayNames.Length);
1582+
Assert.Contains("One", displayNames);
1583+
Assert.Contains("Two", displayNames);
1584+
Assert.Contains("Three", displayNames);
1585+
Assert.Contains("Four", displayNames);
1586+
Assert.Contains("Five", displayNames);
15861587

15871588
var client = app.GetTestClient();
15881589

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,17 @@ public abstract class EndpointBuilder
2828
/// <summary>
2929
/// Gets the <see cref="IServiceProvider"/> associated with the endpoint.
3030
/// </summary>
31-
public IServiceProvider? ServiceProvider { get; set; }
31+
public IServiceProvider ApplicationServices { get; set; } = EmptyServiceProvicer.Instance;
3232

3333
/// <summary>
3434
/// Creates an instance of <see cref="Endpoint"/> from the <see cref="EndpointBuilder"/>.
3535
/// </summary>
3636
/// <returns>The created <see cref="Endpoint"/>.</returns>
3737
public abstract Endpoint Build();
38+
39+
private sealed class EmptyServiceProvicer : IServiceProvider
40+
{
41+
public static EmptyServiceProvicer Instance { get; } = new EmptyServiceProvicer();
42+
public object? GetService(Type serviceType) => null;
43+
}
3844
}

src/Http/Http.Abstractions/src/PublicAPI.Unshipped.txt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
#nullable enable
22
*REMOVED*abstract Microsoft.AspNetCore.Http.HttpResponse.ContentType.get -> string!
33
*REMOVED*Microsoft.AspNetCore.Http.EndpointMetadataCollection.Enumerator.Current.get -> object?
4-
Microsoft.AspNetCore.Builder.EndpointBuilder.ServiceProvider.get -> System.IServiceProvider?
5-
Microsoft.AspNetCore.Builder.EndpointBuilder.ServiceProvider.set -> void
4+
Microsoft.AspNetCore.Builder.EndpointBuilder.ApplicationServices.get -> System.IServiceProvider!
5+
Microsoft.AspNetCore.Builder.EndpointBuilder.ApplicationServices.set -> void
66
Microsoft.AspNetCore.Http.AsParametersAttribute
77
Microsoft.AspNetCore.Http.AsParametersAttribute.AsParametersAttribute() -> void
88
Microsoft.AspNetCore.Http.DefaultRouteHandlerInvocationContext
@@ -18,9 +18,9 @@ Microsoft.AspNetCore.Http.Metadata.IRequestSizeLimitMetadata
1818
Microsoft.AspNetCore.Http.Metadata.IRequestSizeLimitMetadata.MaxRequestBodySize.get -> long?
1919
Microsoft.AspNetCore.Http.RouteHandlerContext
2020
Microsoft.AspNetCore.Http.RouteHandlerContext.ApplicationServices.get -> System.IServiceProvider!
21-
Microsoft.AspNetCore.Http.RouteHandlerContext.EndpointMetadata.get -> Microsoft.AspNetCore.Http.EndpointMetadataCollection!
21+
Microsoft.AspNetCore.Http.RouteHandlerContext.EndpointMetadata.get -> System.Collections.Generic.IList<object!>!
2222
Microsoft.AspNetCore.Http.RouteHandlerContext.MethodInfo.get -> System.Reflection.MethodInfo!
23-
Microsoft.AspNetCore.Http.RouteHandlerContext.RouteHandlerContext(System.Reflection.MethodInfo! methodInfo, Microsoft.AspNetCore.Http.EndpointMetadataCollection! endpointMetadata, System.IServiceProvider! applicationServices) -> void
23+
Microsoft.AspNetCore.Http.RouteHandlerContext.RouteHandlerContext(System.Reflection.MethodInfo! methodInfo, System.Collections.Generic.IList<object!>! endpointMetadata, System.IServiceProvider! applicationServices) -> void
2424
Microsoft.AspNetCore.Http.RouteHandlerFilterDelegate
2525
Microsoft.AspNetCore.Http.RouteHandlerInvocationContext
2626
Microsoft.AspNetCore.Http.RouteHandlerInvocationContext.RouteHandlerInvocationContext() -> void

src/Http/Http.Abstractions/src/RequestDelegateResult.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@ public RequestDelegateResult(RequestDelegate requestDelegate, IReadOnlyList<obje
2323
public RequestDelegate RequestDelegate { get; }
2424

2525
/// <summary>
26-
/// Gets endpoint metadata inferred from creating the <see cref="RequestDelegate" />
26+
/// Gets endpoint metadata inferred from creating the <see cref="RequestDelegate" />. If a non-null
27+
/// RequestDelegateFactoryOptions.EndpointMetadata list was passed in, this will be the same instance.
2728
/// </summary>
2829
public IReadOnlyList<object> EndpointMetadata { get; }
2930
}

src/Http/Http.Abstractions/src/RouteHandlerContext.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// The .NET Foundation licenses this file to you under the MIT license.
33

44
using System.Reflection;
5+
using Microsoft.AspNetCore.Builder;
56

67
namespace Microsoft.AspNetCore.Http;
78

@@ -15,9 +16,9 @@ public sealed class RouteHandlerContext
1516
/// Creates a new instance of the <see cref="RouteHandlerContext"/>.
1617
/// </summary>
1718
/// <param name="methodInfo">The <see cref="MethodInfo"/> associated with the route handler of the current request.</param>
18-
/// <param name="endpointMetadata">The <see cref="EndpointMetadataCollection"/> associated with the endpoint the filter is targeting.</param>
19+
/// <param name="endpointMetadata">The <see cref="EndpointBuilder.Metadata"/> associated with the endpoint the filter is targeting.</param>
1920
/// <param name="applicationServices">The <see cref="IServiceProvider"/> instance used to access the application services.</param>
20-
public RouteHandlerContext(MethodInfo methodInfo, EndpointMetadataCollection endpointMetadata, IServiceProvider applicationServices)
21+
public RouteHandlerContext(MethodInfo methodInfo, IList<object> endpointMetadata, IServiceProvider applicationServices)
2122
{
2223
ArgumentNullException.ThrowIfNull(methodInfo);
2324
ArgumentNullException.ThrowIfNull(endpointMetadata);
@@ -36,7 +37,7 @@ public RouteHandlerContext(MethodInfo methodInfo, EndpointMetadataCollection end
3637
/// <summary>
3738
/// The <see cref="EndpointMetadataCollection"/> associated with the current endpoint.
3839
/// </summary>
39-
public EndpointMetadataCollection EndpointMetadata { get; }
40+
public IList<object> EndpointMetadata { get; }
4041

4142
/// <summary>
4243
/// Gets the <see cref="IServiceProvider"/> instance used to access application services.

src/Http/Http.Extensions/src/PublicAPI.Unshipped.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ Microsoft.AspNetCore.Http.Metadata.IEndpointMetadataProvider
1313
Microsoft.AspNetCore.Http.Metadata.IEndpointMetadataProvider.PopulateMetadata(Microsoft.AspNetCore.Http.Metadata.EndpointMetadataContext! context) -> void
1414
Microsoft.AspNetCore.Http.Metadata.IEndpointParameterMetadataProvider
1515
Microsoft.AspNetCore.Http.Metadata.IEndpointParameterMetadataProvider.PopulateMetadata(Microsoft.AspNetCore.Http.Metadata.EndpointParameterMetadataContext! parameterContext) -> void
16-
Microsoft.AspNetCore.Http.RequestDelegateFactoryOptions.InitialEndpointMetadata.get -> System.Collections.Generic.IEnumerable<object!>?
17-
Microsoft.AspNetCore.Http.RequestDelegateFactoryOptions.InitialEndpointMetadata.init -> void
16+
Microsoft.AspNetCore.Http.RequestDelegateFactoryOptions.EndpointMetadata.get -> System.Collections.Generic.IList<object!>?
17+
Microsoft.AspNetCore.Http.RequestDelegateFactoryOptions.EndpointMetadata.init -> void
1818
Microsoft.AspNetCore.Http.RequestDelegateFactoryOptions.RouteHandlerFilterFactories.get -> System.Collections.Generic.IReadOnlyList<System.Func<Microsoft.AspNetCore.Http.RouteHandlerContext!, Microsoft.AspNetCore.Http.RouteHandlerFilterDelegate!, Microsoft.AspNetCore.Http.RouteHandlerFilterDelegate!>!>?
1919
Microsoft.AspNetCore.Http.RequestDelegateFactoryOptions.RouteHandlerFilterFactories.init -> void
2020
Microsoft.Extensions.DependencyInjection.RouteHandlerJsonServiceExtensions

0 commit comments

Comments
 (0)