Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
38 changes: 12 additions & 26 deletions src/Http/Http.Abstractions/src/EndpointFilterFactoryContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
// 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 @@ -13,34 +12,21 @@ namespace Microsoft.AspNetCore.Http;
public sealed class EndpointFilterFactoryContext
{
/// <summary>
/// Creates a new instance of the <see cref="EndpointFilterFactoryContext"/>.
/// The <see cref="MethodInfo"/> associated with the current route handler, <see cref="RequestDelegate"/> or MVC action.
/// </summary>
/// <param name="methodInfo">The <see cref="MethodInfo"/> associated with the route handler of the current request.</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 EndpointFilterFactoryContext(MethodInfo methodInfo, IList<object> endpointMetadata, IServiceProvider applicationServices)
{
ArgumentNullException.ThrowIfNull(methodInfo);
ArgumentNullException.ThrowIfNull(endpointMetadata);
ArgumentNullException.ThrowIfNull(applicationServices);

MethodInfo = methodInfo;
EndpointMetadata = endpointMetadata;
ApplicationServices = applicationServices;
}

/// <summary>
/// The <see cref="MethodInfo"/> associated with the current route handler.
/// </summary>
public MethodInfo MethodInfo { get; }

/// <summary>
/// The <see cref="EndpointMetadataCollection"/> associated with the current endpoint.
/// </summary>
public IList<object> EndpointMetadata { get; }
/// <remarks>
/// In the future this could support more endpoint types.
/// </remarks>
public required MethodInfo MethodInfo { get; init; }

/// <summary>
/// Gets the <see cref="IServiceProvider"/> instance used to access application services.
/// </summary>
public IServiceProvider ApplicationServices { get; }
public IServiceProvider ApplicationServices { get; init; } = EmptyServiceProvider.Instance;

private sealed class EmptyServiceProvider : IServiceProvider
{
public static EmptyServiceProvider Instance { get; } = new EmptyServiceProvider();
public object? GetService(Type serviceType) => null;
}
}
6 changes: 4 additions & 2 deletions src/Http/Http.Abstractions/src/Extensions/EndpointBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,12 @@ namespace Microsoft.AspNetCore.Builder;
/// </summary>
public abstract class EndpointBuilder
{
private List<Func<EndpointFilterFactoryContext, EndpointFilterDelegate, EndpointFilterDelegate>>? _filterFactories;

/// <summary>
/// Gets the list of filters that apply to this endpoint.
/// </summary>
public IList<Func<EndpointFilterFactoryContext, EndpointFilterDelegate, EndpointFilterDelegate>> FilterFactories { get; } = new List<Func<EndpointFilterFactoryContext, EndpointFilterDelegate, EndpointFilterDelegate>>();
public IList<Func<EndpointFilterFactoryContext, EndpointFilterDelegate, EndpointFilterDelegate>> FilterFactories => _filterFactories ??= new();

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

/// <summary>
/// Creates an instance of <see cref="Endpoint"/> from the <see cref="EndpointBuilder"/>.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// 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;
using Microsoft.AspNetCore.Builder;

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"/> and <see cref="MethodInfo"/>.
/// </summary>
/// <remarks>
/// This method is called by RequestDelegateFactory when creating a <see cref="RequestDelegate"/> and by MVC when creating endpoints for controller actions.
/// This is called for each parameter and return type of the route handler or action with a declared type implementing this interface.
/// 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.
/// </remarks>
/// <param name="method">The <see cref="MethodInfo"/> of the route handler delegate or MVC Action of the endpoint being created.</param>
/// <param name="builder">The <see cref="EndpointBuilder"/> used to construct the endpoint for the given <paramref name="method"/>.</param>
static abstract void PopulateMetadata(MethodInfo method, EndpointBuilder builder);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// 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;
using Microsoft.AspNetCore.Builder;

namespace Microsoft.AspNetCore.Http.Metadata;

/// <summary>
/// Indicates that a type provides a static method that provides <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"/> and <see cref="ParameterInfo"/>.
/// </summary>
/// <remarks>
/// This method is called by RequestDelegateFactory when creating a <see cref="RequestDelegate"/> and by MVC when creating endpoints for controller actions.
/// This is called for each parameter of the route handler or action with a declared type implementing this interface.
/// 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.
/// </remarks>
/// <param name="parameter">The <see cref="ParameterInfo"/> of the route handler delegate or MVC Action of the endpoint being created.</param>
/// <param name="builder">The <see cref="EndpointBuilder"/> used to construct the endpoint for the given <paramref name="parameter"/>.</param>
static abstract void PopulateMetadata(ParameterInfo parameter, EndpointBuilder builder);
}
11 changes: 8 additions & 3 deletions src/Http/Http.Abstractions/src/PublicAPI.Unshipped.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ abstract Microsoft.AspNetCore.Http.EndpointFilterInvocationContext.Arguments.get
abstract Microsoft.AspNetCore.Http.EndpointFilterInvocationContext.GetArgument<T>(int index) -> T
abstract Microsoft.AspNetCore.Http.EndpointFilterInvocationContext.HttpContext.get -> Microsoft.AspNetCore.Http.HttpContext!
Microsoft.AspNetCore.Builder.EndpointBuilder.ApplicationServices.get -> System.IServiceProvider!
Microsoft.AspNetCore.Builder.EndpointBuilder.ApplicationServices.set -> void
Microsoft.AspNetCore.Builder.EndpointBuilder.ApplicationServices.init -> void
Microsoft.AspNetCore.Builder.EndpointBuilder.FilterFactories.get -> System.Collections.Generic.IList<System.Func<Microsoft.AspNetCore.Http.EndpointFilterFactoryContext!, Microsoft.AspNetCore.Http.EndpointFilterDelegate!, Microsoft.AspNetCore.Http.EndpointFilterDelegate!>!>!
Microsoft.AspNetCore.Builder.IEndpointConventionBuilder.Finally(System.Action<Microsoft.AspNetCore.Builder.EndpointBuilder!>! finallyConvention) -> void
Microsoft.AspNetCore.Http.AsParametersAttribute
Expand All @@ -16,9 +16,10 @@ Microsoft.AspNetCore.Http.DefaultEndpointFilterInvocationContext.DefaultEndpoint
Microsoft.AspNetCore.Http.EndpointFilterDelegate
Microsoft.AspNetCore.Http.EndpointFilterFactoryContext
Microsoft.AspNetCore.Http.EndpointFilterFactoryContext.ApplicationServices.get -> System.IServiceProvider!
Microsoft.AspNetCore.Http.EndpointFilterFactoryContext.EndpointFilterFactoryContext(System.Reflection.MethodInfo! methodInfo, System.Collections.Generic.IList<object!>! endpointMetadata, System.IServiceProvider! applicationServices) -> void
Microsoft.AspNetCore.Http.EndpointFilterFactoryContext.EndpointMetadata.get -> System.Collections.Generic.IList<object!>!
Microsoft.AspNetCore.Http.EndpointFilterFactoryContext.ApplicationServices.init -> void
Microsoft.AspNetCore.Http.EndpointFilterFactoryContext.EndpointFilterFactoryContext() -> void
Microsoft.AspNetCore.Http.EndpointFilterFactoryContext.MethodInfo.get -> System.Reflection.MethodInfo!
Microsoft.AspNetCore.Http.EndpointFilterFactoryContext.MethodInfo.init -> void
Microsoft.AspNetCore.Http.EndpointFilterInvocationContext
Microsoft.AspNetCore.Http.EndpointFilterInvocationContext.EndpointFilterInvocationContext() -> void
Microsoft.AspNetCore.Http.EndpointMetadataCollection.Enumerator.Current.get -> object!
Expand Down Expand Up @@ -68,6 +69,10 @@ abstract Microsoft.AspNetCore.Http.HttpResponse.ContentType.get -> string?
Microsoft.AspNetCore.Http.Metadata.ISkipStatusCodePagesMetadata
Microsoft.AspNetCore.Http.Metadata.IEndpointDescriptionMetadata
Microsoft.AspNetCore.Http.Metadata.IEndpointDescriptionMetadata.Description.get -> string!
Microsoft.AspNetCore.Http.Metadata.IEndpointMetadataProvider
Microsoft.AspNetCore.Http.Metadata.IEndpointMetadataProvider.PopulateMetadata(System.Reflection.MethodInfo! method, Microsoft.AspNetCore.Builder.EndpointBuilder! builder) -> void
Microsoft.AspNetCore.Http.Metadata.IEndpointParameterMetadataProvider
Microsoft.AspNetCore.Http.Metadata.IEndpointParameterMetadataProvider.PopulateMetadata(System.Reflection.ParameterInfo! parameter, Microsoft.AspNetCore.Builder.EndpointBuilder! builder) -> void
Microsoft.AspNetCore.Http.Metadata.IEndpointSummaryMetadata
Microsoft.AspNetCore.Http.Metadata.IEndpointSummaryMetadata.Summary.get -> string!
Microsoft.AspNetCore.Mvc.ProblemDetails
Expand Down
44 changes: 0 additions & 44 deletions src/Http/Http.Extensions/src/EndpointMetadataContext.cs

This file was deleted.

44 changes: 0 additions & 44 deletions src/Http/Http.Extensions/src/EndpointParameterMetadataContext.cs

This file was deleted.

23 changes: 0 additions & 23 deletions src/Http/Http.Extensions/src/IEndpointMetadataProvider.cs

This file was deleted.

23 changes: 0 additions & 23 deletions src/Http/Http.Extensions/src/IEndpointParameterMetadataProvider.cs

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<Description>ASP.NET Core common extension methods for HTTP abstractions, HTTP headers, HTTP request/response, and session state.</Description>
Expand All @@ -14,6 +14,7 @@
<ItemGroup>
<Compile Include="$(SharedSourceRoot)ObjectMethodExecutor\**\*.cs" LinkBase="Shared"/>
<Compile Include="$(SharedSourceRoot)ParameterBindingMethodCache.cs" LinkBase="Shared"/>
<Compile Include="$(SharedSourceRoot)EndpointMetadataPopulator.cs" LinkBase="Shared"/>
<Compile Include="$(SharedSourceRoot)PropertyAsParameterInfo.cs" LinkBase="Shared"/>
<Compile Include="..\..\Shared\StreamCopyOperationInternal.cs" LinkBase="Shared" />
<Compile Include="$(SharedSourceRoot)RoutingMetadata\AcceptsMetadata.cs" LinkBase="Shared" />
Expand Down
Loading