-
Notifications
You must be signed in to change notification settings - Fork 10.4k
Implement IProvideEndpointMetadata & IProvideEndpointParameterMetadata #40926
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
Changes from 15 commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
d326814
Add interfaces for providing metadata from route handler types
DamianEdwards 8b9eacd
Update RequestDelegateFactory to get metadata from method parameter, …
DamianEdwards d16183e
Set exception message
DamianEdwards 336b790
Add unit tests for metadata interfaces
DamianEdwards 5765204
PR feedback
DamianEdwards 784440b
Remove gathering metadata from method attributes
DamianEdwards 28b1bea
Remove public access modifier on static abstract method definitions
DamianEdwards 2e46a26
API review feedback
DamianEdwards 0481d3b
WIP
DamianEdwards 5327990
API review feedback
DamianEdwards 1dfa5e0
Remove unneeded property
DamianEdwards 0b516ba
Doc comment fixup
DamianEdwards e0d3778
Move processing of IProvideEndpointMetadata to RequestDelegateFactory
DamianEdwards 18ee92a
PR feedback
DamianEdwards d0fed85
Fix setter
DamianEdwards 66cc500
Addressing PR feedback
DamianEdwards 0ffe8bd
PR feedback
DamianEdwards 4c93fe7
Remove commented out code
DamianEdwards de7d926
Seal EndpointParameterMetadataContext
DamianEdwards 7e8273a
PR feedback
DamianEdwards File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
|
||
using System.Reflection; | ||
|
||
namespace Microsoft.AspNetCore.Http.Metadata; | ||
|
||
/// <summary> | ||
/// Represents the information accessible during endpoint creation by types that implement <see cref="IEndpointMetadataProvider"/>. | ||
/// </summary> | ||
public sealed class EndpointMetadataContext | ||
{ | ||
/// <summary> | ||
/// Gets the <see cref="MethodInfo"/> associated with the current route handler. | ||
/// </summary> | ||
public MethodInfo? Method { get; init; } | ||
|
||
/// <summary> | ||
/// Gets the <see cref="IServiceProvider"/> instance used to access application services. | ||
/// </summary> | ||
public IServiceProvider? Services { get; init; } | ||
|
||
/// <summary> | ||
/// Gets the objects that will be added to the metadata of the endpoint. | ||
/// </summary> | ||
public IList<object>? EndpointMetadata { get; init; } | ||
} |
27 changes: 27 additions & 0 deletions
27
src/Http/Http.Extensions/src/EndpointParameterMetadataContext.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
|
||
using System.Reflection; | ||
|
||
namespace Microsoft.AspNetCore.Http.Metadata; | ||
|
||
/// <summary> | ||
/// Represents the information accessible during endpoint creation by types that implement <see cref="IEndpointParameterMetadataProvider"/>. | ||
/// </summary> | ||
public class EndpointParameterMetadataContext | ||
{ | ||
/// <summary> | ||
/// Gets the parameter of the route handler delegate of the endpoint being created. | ||
/// </summary> | ||
public ParameterInfo? Parameter { get; set; } // set to allow re-use | ||
DamianEdwards marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
/// <summary> | ||
/// Gets the <see cref="MethodInfo"/> associated with the current route handler. | ||
/// </summary> | ||
public IServiceProvider? Services { get; init; } | ||
|
||
/// <summary> | ||
/// Gets the objects that will be added to the metadata of the endpoint. | ||
/// </summary> | ||
public IList<object>? EndpointMetadata { get; init; } | ||
DamianEdwards marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
|
||
namespace Microsoft.AspNetCore.Http.Metadata; | ||
|
||
/// <summary> | ||
/// Indicates that a type provides a static method that provides <see cref="Endpoint"/> metadata when declared as a parameter type or the | ||
/// returned type of an <see cref="Endpoint"/> route handler delegate. | ||
/// </summary> | ||
public interface IEndpointMetadataProvider | ||
{ | ||
/// <summary> | ||
/// Populates metadata for the related <see cref="Endpoint"/>. | ||
/// </summary> | ||
/// <param name="context">The <see cref="EndpointMetadataContext"/>.</param> | ||
static abstract void PopulateMetadata(EndpointMetadataContext context); | ||
} |
17 changes: 17 additions & 0 deletions
17
src/Http/Http.Extensions/src/IEndpointParameterMetadataProvider.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
|
||
namespace Microsoft.AspNetCore.Http.Metadata; | ||
|
||
/// <summary> | ||
/// Indicates that a type provides a static method that returns <see cref="Endpoint"/> metadata when declared as the | ||
/// parameter type of an <see cref="Endpoint"/> route handler delegate. | ||
/// </summary> | ||
public interface IEndpointParameterMetadataProvider | ||
{ | ||
/// <summary> | ||
/// Populates metadata for the related <see cref="Endpoint"/>. | ||
DamianEdwards marked this conversation as resolved.
Show resolved
Hide resolved
|
||
/// </summary> | ||
/// <param name="parameterContext">The <see cref="EndpointParameterMetadataContext"/>.</param> | ||
static abstract void PopulateMetadata(EndpointParameterMetadataContext parameterContext); | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.