Skip to content

Commit 067c6c2

Browse files
authored
[release/7.0] Add and use RDF.InferMetadata and update new PopulateMetadata API (#43543)
1 parent c279906 commit 067c6c2

File tree

80 files changed

+1840
-1472
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

80 files changed

+1840
-1472
lines changed

src/Http/Http.Abstractions/src/EndpointFilterFactoryContext.cs

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

44
using System.Reflection;
5-
using Microsoft.AspNetCore.Builder;
65

76
namespace Microsoft.AspNetCore.Http;
87

@@ -13,34 +12,21 @@ namespace Microsoft.AspNetCore.Http;
1312
public sealed class EndpointFilterFactoryContext
1413
{
1514
/// <summary>
16-
/// Creates a new instance of the <see cref="EndpointFilterFactoryContext"/>.
15+
/// The <see cref="MethodInfo"/> associated with the current route handler, <see cref="RequestDelegate"/> or MVC action.
1716
/// </summary>
18-
/// <param name="methodInfo">The <see cref="MethodInfo"/> associated with the route handler of the current request.</param>
19-
/// <param name="endpointMetadata">The <see cref="EndpointBuilder.Metadata"/> associated with the endpoint the filter is targeting.</param>
20-
/// <param name="applicationServices">The <see cref="IServiceProvider"/> instance used to access the application services.</param>
21-
public EndpointFilterFactoryContext(MethodInfo methodInfo, IList<object> endpointMetadata, IServiceProvider applicationServices)
22-
{
23-
ArgumentNullException.ThrowIfNull(methodInfo);
24-
ArgumentNullException.ThrowIfNull(endpointMetadata);
25-
ArgumentNullException.ThrowIfNull(applicationServices);
26-
27-
MethodInfo = methodInfo;
28-
EndpointMetadata = endpointMetadata;
29-
ApplicationServices = applicationServices;
30-
}
31-
32-
/// <summary>
33-
/// The <see cref="MethodInfo"/> associated with the current route handler.
34-
/// </summary>
35-
public MethodInfo MethodInfo { get; }
36-
37-
/// <summary>
38-
/// The <see cref="EndpointMetadataCollection"/> associated with the current endpoint.
39-
/// </summary>
40-
public IList<object> EndpointMetadata { get; }
17+
/// <remarks>
18+
/// In the future this could support more endpoint types.
19+
/// </remarks>
20+
public required MethodInfo MethodInfo { get; init; }
4121

4222
/// <summary>
4323
/// Gets the <see cref="IServiceProvider"/> instance used to access application services.
4424
/// </summary>
45-
public IServiceProvider ApplicationServices { get; }
25+
public IServiceProvider ApplicationServices { get; init; } = EmptyServiceProvider.Instance;
26+
27+
private sealed class EmptyServiceProvider : IServiceProvider
28+
{
29+
public static EmptyServiceProvider Instance { get; } = new EmptyServiceProvider();
30+
public object? GetService(Type serviceType) => null;
31+
}
4632
}

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,12 @@ namespace Microsoft.AspNetCore.Builder;
1010
/// </summary>
1111
public abstract class EndpointBuilder
1212
{
13+
private List<Func<EndpointFilterFactoryContext, EndpointFilterDelegate, EndpointFilterDelegate>>? _filterFactories;
14+
1315
/// <summary>
1416
/// Gets the list of filters that apply to this endpoint.
1517
/// </summary>
16-
public IList<Func<EndpointFilterFactoryContext, EndpointFilterDelegate, EndpointFilterDelegate>> FilterFactories { get; } = new List<Func<EndpointFilterFactoryContext, EndpointFilterDelegate, EndpointFilterDelegate>>();
18+
public IList<Func<EndpointFilterFactoryContext, EndpointFilterDelegate, EndpointFilterDelegate>> FilterFactories => _filterFactories ??= new();
1719

1820
/// <summary>
1921
/// Gets or sets the delegate used to process requests for the endpoint.
@@ -33,7 +35,7 @@ public abstract class EndpointBuilder
3335
/// <summary>
3436
/// Gets the <see cref="IServiceProvider"/> associated with the endpoint.
3537
/// </summary>
36-
public IServiceProvider ApplicationServices { get; set; } = EmptyServiceProvider.Instance;
38+
public IServiceProvider ApplicationServices { get; init; } = EmptyServiceProvider.Instance;
3739

3840
/// <summary>
3941
/// Creates an instance of <see cref="Endpoint"/> from the <see cref="EndpointBuilder"/>.
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
4+
using System.Reflection;
5+
using Microsoft.AspNetCore.Builder;
6+
7+
namespace Microsoft.AspNetCore.Http.Metadata;
8+
9+
/// <summary>
10+
/// Indicates that a type provides a static method that provides <see cref="Endpoint"/> metadata when declared as a parameter type or the
11+
/// returned type of an <see cref="Endpoint"/> route handler delegate.
12+
/// </summary>
13+
public interface IEndpointMetadataProvider
14+
{
15+
/// <summary>
16+
/// Populates metadata for the related <see cref="Endpoint"/> and <see cref="MethodInfo"/>.
17+
/// </summary>
18+
/// <remarks>
19+
/// This method is called by RequestDelegateFactory when creating a <see cref="RequestDelegate"/> and by MVC when creating endpoints for controller actions.
20+
/// This is called for each parameter and return type of the route handler or action with a declared type implementing this interface.
21+
/// Add or remove objects on the <see cref="EndpointBuilder.Metadata"/> property of the <paramref name="builder"/> to modify the <see cref="Endpoint.Metadata"/> being built.
22+
/// </remarks>
23+
/// <param name="method">The <see cref="MethodInfo"/> of the route handler delegate or MVC Action of the endpoint being created.</param>
24+
/// <param name="builder">The <see cref="EndpointBuilder"/> used to construct the endpoint for the given <paramref name="method"/>.</param>
25+
static abstract void PopulateMetadata(MethodInfo method, EndpointBuilder builder);
26+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
4+
using System.Reflection;
5+
using Microsoft.AspNetCore.Builder;
6+
7+
namespace Microsoft.AspNetCore.Http.Metadata;
8+
9+
/// <summary>
10+
/// Indicates that a type provides a static method that provides <see cref="Endpoint"/> metadata when declared as the
11+
/// parameter type of an <see cref="Endpoint"/> route handler delegate.
12+
/// </summary>
13+
public interface IEndpointParameterMetadataProvider
14+
{
15+
/// <summary>
16+
/// Populates metadata for the related <see cref="Endpoint"/> and <see cref="ParameterInfo"/>.
17+
/// </summary>
18+
/// <remarks>
19+
/// This method is called by RequestDelegateFactory when creating a <see cref="RequestDelegate"/> and by MVC when creating endpoints for controller actions.
20+
/// This is called for each parameter of the route handler or action with a declared type implementing this interface.
21+
/// Add or remove objects on the <see cref="EndpointBuilder.Metadata"/> property of the <paramref name="builder"/> to modify the <see cref="Endpoint.Metadata"/> being built.
22+
/// </remarks>
23+
/// <param name="parameter">The <see cref="ParameterInfo"/> of the route handler delegate or MVC Action of the endpoint being created.</param>
24+
/// <param name="builder">The <see cref="EndpointBuilder"/> used to construct the endpoint for the given <paramref name="parameter"/>.</param>
25+
static abstract void PopulateMetadata(ParameterInfo parameter, EndpointBuilder builder);
26+
}

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

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ abstract Microsoft.AspNetCore.Http.EndpointFilterInvocationContext.Arguments.get
55
abstract Microsoft.AspNetCore.Http.EndpointFilterInvocationContext.GetArgument<T>(int index) -> T
66
abstract Microsoft.AspNetCore.Http.EndpointFilterInvocationContext.HttpContext.get -> Microsoft.AspNetCore.Http.HttpContext!
77
Microsoft.AspNetCore.Builder.EndpointBuilder.ApplicationServices.get -> System.IServiceProvider!
8-
Microsoft.AspNetCore.Builder.EndpointBuilder.ApplicationServices.set -> void
8+
Microsoft.AspNetCore.Builder.EndpointBuilder.ApplicationServices.init -> void
99
Microsoft.AspNetCore.Builder.EndpointBuilder.FilterFactories.get -> System.Collections.Generic.IList<System.Func<Microsoft.AspNetCore.Http.EndpointFilterFactoryContext!, Microsoft.AspNetCore.Http.EndpointFilterDelegate!, Microsoft.AspNetCore.Http.EndpointFilterDelegate!>!>!
1010
Microsoft.AspNetCore.Builder.IEndpointConventionBuilder.Finally(System.Action<Microsoft.AspNetCore.Builder.EndpointBuilder!>! finallyConvention) -> void
1111
Microsoft.AspNetCore.Http.AsParametersAttribute
@@ -16,9 +16,10 @@ Microsoft.AspNetCore.Http.DefaultEndpointFilterInvocationContext.DefaultEndpoint
1616
Microsoft.AspNetCore.Http.EndpointFilterDelegate
1717
Microsoft.AspNetCore.Http.EndpointFilterFactoryContext
1818
Microsoft.AspNetCore.Http.EndpointFilterFactoryContext.ApplicationServices.get -> System.IServiceProvider!
19-
Microsoft.AspNetCore.Http.EndpointFilterFactoryContext.EndpointFilterFactoryContext(System.Reflection.MethodInfo! methodInfo, System.Collections.Generic.IList<object!>! endpointMetadata, System.IServiceProvider! applicationServices) -> void
20-
Microsoft.AspNetCore.Http.EndpointFilterFactoryContext.EndpointMetadata.get -> System.Collections.Generic.IList<object!>!
19+
Microsoft.AspNetCore.Http.EndpointFilterFactoryContext.ApplicationServices.init -> void
20+
Microsoft.AspNetCore.Http.EndpointFilterFactoryContext.EndpointFilterFactoryContext() -> void
2121
Microsoft.AspNetCore.Http.EndpointFilterFactoryContext.MethodInfo.get -> System.Reflection.MethodInfo!
22+
Microsoft.AspNetCore.Http.EndpointFilterFactoryContext.MethodInfo.init -> void
2223
Microsoft.AspNetCore.Http.EndpointFilterInvocationContext
2324
Microsoft.AspNetCore.Http.EndpointFilterInvocationContext.EndpointFilterInvocationContext() -> void
2425
Microsoft.AspNetCore.Http.EndpointMetadataCollection.Enumerator.Current.get -> object!
@@ -68,6 +69,10 @@ abstract Microsoft.AspNetCore.Http.HttpResponse.ContentType.get -> string?
6869
Microsoft.AspNetCore.Http.Metadata.ISkipStatusCodePagesMetadata
6970
Microsoft.AspNetCore.Http.Metadata.IEndpointDescriptionMetadata
7071
Microsoft.AspNetCore.Http.Metadata.IEndpointDescriptionMetadata.Description.get -> string!
72+
Microsoft.AspNetCore.Http.Metadata.IEndpointMetadataProvider
73+
Microsoft.AspNetCore.Http.Metadata.IEndpointMetadataProvider.PopulateMetadata(System.Reflection.MethodInfo! method, Microsoft.AspNetCore.Builder.EndpointBuilder! builder) -> void
74+
Microsoft.AspNetCore.Http.Metadata.IEndpointParameterMetadataProvider
75+
Microsoft.AspNetCore.Http.Metadata.IEndpointParameterMetadataProvider.PopulateMetadata(System.Reflection.ParameterInfo! parameter, Microsoft.AspNetCore.Builder.EndpointBuilder! builder) -> void
7176
Microsoft.AspNetCore.Http.Metadata.IEndpointSummaryMetadata
7277
Microsoft.AspNetCore.Http.Metadata.IEndpointSummaryMetadata.Summary.get -> string!
7378
Microsoft.AspNetCore.Mvc.ProblemDetails

src/Http/Http.Extensions/src/EndpointMetadataContext.cs

Lines changed: 0 additions & 44 deletions
This file was deleted.

src/Http/Http.Extensions/src/EndpointParameterMetadataContext.cs

Lines changed: 0 additions & 44 deletions
This file was deleted.

src/Http/Http.Extensions/src/IEndpointMetadataProvider.cs

Lines changed: 0 additions & 23 deletions
This file was deleted.

src/Http/Http.Extensions/src/IEndpointParameterMetadataProvider.cs

Lines changed: 0 additions & 23 deletions
This file was deleted.

src/Http/Http.Extensions/src/Microsoft.AspNetCore.Http.Extensions.csproj

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<Project Sdk="Microsoft.NET.Sdk">
1+
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
44
<Description>ASP.NET Core common extension methods for HTTP abstractions, HTTP headers, HTTP request/response, and session state.</Description>
@@ -14,6 +14,7 @@
1414
<ItemGroup>
1515
<Compile Include="$(SharedSourceRoot)ObjectMethodExecutor\**\*.cs" LinkBase="Shared"/>
1616
<Compile Include="$(SharedSourceRoot)ParameterBindingMethodCache.cs" LinkBase="Shared"/>
17+
<Compile Include="$(SharedSourceRoot)EndpointMetadataPopulator.cs" LinkBase="Shared"/>
1718
<Compile Include="$(SharedSourceRoot)PropertyAsParameterInfo.cs" LinkBase="Shared"/>
1819
<Compile Include="..\..\Shared\StreamCopyOperationInternal.cs" LinkBase="Shared" />
1920
<Compile Include="$(SharedSourceRoot)RoutingMetadata\AcceptsMetadata.cs" LinkBase="Shared" />

0 commit comments

Comments
 (0)