Skip to content

[Route Groups] Support AddFilter, WithOpenApi and other additive conventions #42195

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 23 commits into from
Jun 21, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
79803dd
Add EndpointDataSource.GetGroupedEndpoints
halter73 Jun 10, 2022
d3f0bfd
TBuilderify AddFilter and WithOpenApi
halter73 Jun 15, 2022
e1c8b91
Fix missed ServiceProvider -> ApplicationServices
halter73 Jun 15, 2022
97a5ada
Fix some tests and doc comments
halter73 Jun 16, 2022
888f3c9
Fix CompositeEndpointDataSource.HandleChange ordering
halter73 Jun 16, 2022
59c9daf
Address PR review feedback
halter73 Jun 17, 2022
b986444
Address more PR feedback
halter73 Jun 17, 2022
1c5feef
Move MapMethods logic into RouteEndpointDataSource
halter73 Jun 17, 2022
dde086f
Merge remote-tracking branch 'origin/main' into halter73/41427
halter73 Jun 17, 2022
539097d
Fix internal doc comment cref
halter73 Jun 17, 2022
3da2136
Move MapFallback logic to RouteEndpointDataSource too
halter73 Jun 17, 2022
4e88138
GetGroupedEndpoints -> GetEndpointGroup
halter73 Jun 17, 2022
8afc04e
Fix build
halter73 Jun 17, 2022
30c3cf7
I thought I already fixed this lol
halter73 Jun 17, 2022
77a6a2c
cleanup
halter73 Jun 18, 2022
1bb70c8
polish
halter73 Jun 18, 2022
a0ff534
Clean up doc comments
halter73 Jun 18, 2022
b0c8b1b
Address straightforward PR feedback
halter73 Jun 19, 2022
1aa70bb
Add filters to RouteEndpointBuilder
halter73 Jun 20, 2022
e9f9ee5
Merge remote-tracking branch 'origin/main' into halter73/41427
halter73 Jun 20, 2022
9760dcb
Remove redundant RequestDelegate returnType check
halter73 Jun 20, 2022
f094c48
Fix merge conflict with RDF AOT changes
halter73 Jun 20, 2022
8e4ece6
Add missed MapHealthChecks suppression
halter73 Jun 20, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1577,12 +1577,13 @@ public async Task BranchingPipelineHasOwnRoutes()
app.Start();

var ds = app.Services.GetRequiredService<EndpointDataSource>();
Assert.Equal(5, ds.Endpoints.Count);
Assert.Equal("One", ds.Endpoints[0].DisplayName);
Assert.Equal("Two", ds.Endpoints[1].DisplayName);
Assert.Equal("Three", ds.Endpoints[2].DisplayName);
Assert.Equal("Four", ds.Endpoints[3].DisplayName);
Assert.Equal("Five", ds.Endpoints[4].DisplayName);
var displayNames = ds.Endpoints.Select(e => e.DisplayName).ToArray();
Assert.Equal(5, displayNames.Length);
Assert.Contains("One", displayNames);
Assert.Contains("Two", displayNames);
Assert.Contains("Three", displayNames);
Assert.Contains("Four", displayNames);
Assert.Contains("Five", displayNames);

var client = app.GetTestClient();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,17 @@ public abstract class EndpointBuilder
/// <summary>
/// Gets the <see cref="IServiceProvider"/> associated with the endpoint.
/// </summary>
public IServiceProvider? ServiceProvider { get; set; }
public IServiceProvider ApplicationServices { get; set; } = EmptyServiceProvicer.Instance;

/// <summary>
/// Creates an instance of <see cref="Endpoint"/> from the <see cref="EndpointBuilder"/>.
/// </summary>
/// <returns>The created <see cref="Endpoint"/>.</returns>
public abstract Endpoint Build();

private sealed class EmptyServiceProvicer : IServiceProvider
{
public static EmptyServiceProvicer Instance { get; } = new EmptyServiceProvicer();
public object? GetService(Type serviceType) => null;
}
}
8 changes: 4 additions & 4 deletions src/Http/Http.Abstractions/src/PublicAPI.Unshipped.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#nullable enable
*REMOVED*abstract Microsoft.AspNetCore.Http.HttpResponse.ContentType.get -> string!
*REMOVED*Microsoft.AspNetCore.Http.EndpointMetadataCollection.Enumerator.Current.get -> object?
Microsoft.AspNetCore.Builder.EndpointBuilder.ServiceProvider.get -> System.IServiceProvider?
Microsoft.AspNetCore.Builder.EndpointBuilder.ServiceProvider.set -> void
Microsoft.AspNetCore.Builder.EndpointBuilder.ApplicationServices.get -> System.IServiceProvider!
Microsoft.AspNetCore.Builder.EndpointBuilder.ApplicationServices.set -> void
Microsoft.AspNetCore.Http.AsParametersAttribute
Microsoft.AspNetCore.Http.AsParametersAttribute.AsParametersAttribute() -> void
Microsoft.AspNetCore.Http.DefaultRouteHandlerInvocationContext
Expand All @@ -18,9 +18,9 @@ Microsoft.AspNetCore.Http.Metadata.IRequestSizeLimitMetadata
Microsoft.AspNetCore.Http.Metadata.IRequestSizeLimitMetadata.MaxRequestBodySize.get -> long?
Microsoft.AspNetCore.Http.RouteHandlerContext
Microsoft.AspNetCore.Http.RouteHandlerContext.ApplicationServices.get -> System.IServiceProvider!
Microsoft.AspNetCore.Http.RouteHandlerContext.EndpointMetadata.get -> Microsoft.AspNetCore.Http.EndpointMetadataCollection!
Microsoft.AspNetCore.Http.RouteHandlerContext.EndpointMetadata.get -> System.Collections.Generic.IList<object!>!
Microsoft.AspNetCore.Http.RouteHandlerContext.MethodInfo.get -> System.Reflection.MethodInfo!
Microsoft.AspNetCore.Http.RouteHandlerContext.RouteHandlerContext(System.Reflection.MethodInfo! methodInfo, Microsoft.AspNetCore.Http.EndpointMetadataCollection! endpointMetadata, System.IServiceProvider! applicationServices) -> void
Microsoft.AspNetCore.Http.RouteHandlerContext.RouteHandlerContext(System.Reflection.MethodInfo! methodInfo, System.Collections.Generic.IList<object!>! endpointMetadata, System.IServiceProvider! applicationServices) -> void
Microsoft.AspNetCore.Http.RouteHandlerFilterDelegate
Microsoft.AspNetCore.Http.RouteHandlerInvocationContext
Microsoft.AspNetCore.Http.RouteHandlerInvocationContext.RouteHandlerInvocationContext() -> void
Expand Down
3 changes: 2 additions & 1 deletion src/Http/Http.Abstractions/src/RequestDelegateResult.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ public RequestDelegateResult(RequestDelegate requestDelegate, IReadOnlyList<obje
public RequestDelegate RequestDelegate { get; }

/// <summary>
/// Gets endpoint metadata inferred from creating the <see cref="RequestDelegate" />
/// Gets endpoint metadata inferred from creating the <see cref="RequestDelegate" />. If a non-null
/// RequestDelegateFactoryOptions.EndpointMetadata list was passed in, this will be the same instance.
/// </summary>
public IReadOnlyList<object> EndpointMetadata { get; }
}
7 changes: 4 additions & 3 deletions src/Http/Http.Abstractions/src/RouteHandlerContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// The .NET Foundation licenses this file to you under the MIT license.

using System.Reflection;
using Microsoft.AspNetCore.Builder;

namespace Microsoft.AspNetCore.Http;

Expand All @@ -15,9 +16,9 @@ public sealed class RouteHandlerContext
/// Creates a new instance of the <see cref="RouteHandlerContext"/>.
/// </summary>
/// <param name="methodInfo">The <see cref="MethodInfo"/> associated with the route handler of the current request.</param>
/// <param name="endpointMetadata">The <see cref="EndpointMetadataCollection"/> associated with the endpoint the filter is targeting.</param>
/// <param name="endpointMetadata">The <see cref="EndpointBuilder.Metadata"/> associated with the endpoint the filter is targeting.</param>
/// <param name="applicationServices">The <see cref="IServiceProvider"/> instance used to access the application services.</param>
public RouteHandlerContext(MethodInfo methodInfo, EndpointMetadataCollection endpointMetadata, IServiceProvider applicationServices)
public RouteHandlerContext(MethodInfo methodInfo, IList<object> endpointMetadata, IServiceProvider applicationServices)
{
ArgumentNullException.ThrowIfNull(methodInfo);
ArgumentNullException.ThrowIfNull(endpointMetadata);
Expand All @@ -36,7 +37,7 @@ public RouteHandlerContext(MethodInfo methodInfo, EndpointMetadataCollection end
/// <summary>
/// The <see cref="EndpointMetadataCollection"/> associated with the current endpoint.
/// </summary>
public EndpointMetadataCollection EndpointMetadata { get; }
public IList<object> EndpointMetadata { get; }

/// <summary>
/// Gets the <see cref="IServiceProvider"/> instance used to access application services.
Expand Down
4 changes: 2 additions & 2 deletions src/Http/Http.Extensions/src/PublicAPI.Unshipped.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ Microsoft.AspNetCore.Http.Metadata.IEndpointMetadataProvider
Microsoft.AspNetCore.Http.Metadata.IEndpointMetadataProvider.PopulateMetadata(Microsoft.AspNetCore.Http.Metadata.EndpointMetadataContext! context) -> void
Microsoft.AspNetCore.Http.Metadata.IEndpointParameterMetadataProvider
Microsoft.AspNetCore.Http.Metadata.IEndpointParameterMetadataProvider.PopulateMetadata(Microsoft.AspNetCore.Http.Metadata.EndpointParameterMetadataContext! parameterContext) -> void
Microsoft.AspNetCore.Http.RequestDelegateFactoryOptions.InitialEndpointMetadata.get -> System.Collections.Generic.IEnumerable<object!>?
Microsoft.AspNetCore.Http.RequestDelegateFactoryOptions.InitialEndpointMetadata.init -> void
Microsoft.AspNetCore.Http.RequestDelegateFactoryOptions.EndpointMetadata.get -> System.Collections.Generic.IList<object!>?
Microsoft.AspNetCore.Http.RequestDelegateFactoryOptions.EndpointMetadata.init -> void
Microsoft.AspNetCore.Http.RequestDelegateFactoryOptions.RouteHandlerFilterFactories.get -> System.Collections.Generic.IReadOnlyList<System.Func<Microsoft.AspNetCore.Http.RouteHandlerContext!, Microsoft.AspNetCore.Http.RouteHandlerFilterDelegate!, Microsoft.AspNetCore.Http.RouteHandlerFilterDelegate!>!>?
Microsoft.AspNetCore.Http.RequestDelegateFactoryOptions.RouteHandlerFilterFactories.init -> void
Microsoft.Extensions.DependencyInjection.RouteHandlerJsonServiceExtensions
Expand Down
Loading