Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,26 @@ Microsoft.AspNetCore.Http.HttpResponse</Description>

<ItemGroup>
<InternalsVisibleTo Include="Microsoft.AspNetCore.Http.Abstractions.Microbenchmarks" />
<InternalsVisibleTo Include="Microsoft.AspNetCore.Http.Extensions" />
</ItemGroup>

<ItemGroup>
<None Update="RouteHandlerInvocationContextOfT.tt">
<Generator>TextTemplatingFileGenerator</Generator>
<LastGenOutput>RouteHandlerInvocationContextOfT.cs</LastGenOutput>
</None>
</ItemGroup>

<ItemGroup>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if we can include this in the global directory.props

cc @dougbu

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You mean notice a project contains a .tt file and add the <Service /> element @davidfowl❔ That may work but VS would rewrite it the next time someone opens the project IIRC.

We only have 3 projects containing this <Service /> after this PR. How big an issue is this❔

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not an issue, I would just like to clean it up as we plan to code generate more things.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's up to you @davidfowl whether to centralize things in this PR. I recommend testing if the code in our root Directory.Build.props prevents VS rewriting the project to list the <Service/>. If "Save All" is fine after adding a new .tt file, you're good to go. Otherwise, the extra code will become redundant and something we'll end up fighting.

The specific approach would be something like

<ItemGroup>
  <_GeneratorSources Include="$(MSBuildProjectDirectory)\**\*.tt" />
</ItemGroup>
<ItemGroup>
  <Service Condition=" '@(_GeneratorSources->Count()) ' != '0' " Include="{508349b6-6b84-4df5-91f0-309beebad82d}" />
</ItemGroup>

<Service Include="{508349b6-6b84-4df5-91f0-309beebad82d}" />
</ItemGroup>

<ItemGroup>
<Compile Update="RouteHandlerInvocationContextOfT.cs">
<DesignTime>True</DesignTime>
<AutoGen>True</AutoGen>
<DependentUpon>RouteHandlerInvocationContextOfT.tt</DependentUpon>
</Compile>
</ItemGroup>

</Project>
5 changes: 3 additions & 2 deletions src/Http/Http.Abstractions/src/PublicAPI.Unshipped.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@ Microsoft.AspNetCore.Http.RouteHandlerContext.MethodInfo.get -> System.Reflectio
Microsoft.AspNetCore.Http.RouteHandlerContext.RouteHandlerContext(System.Reflection.MethodInfo! methodInfo, Microsoft.AspNetCore.Http.EndpointMetadataCollection! endpointMetadata) -> void
Microsoft.AspNetCore.Http.RouteHandlerFilterDelegate
Microsoft.AspNetCore.Http.RouteHandlerInvocationContext
Microsoft.AspNetCore.Http.RouteHandlerInvocationContext.HttpContext.get -> Microsoft.AspNetCore.Http.HttpContext!
Microsoft.AspNetCore.Http.RouteHandlerInvocationContext.Parameters.get -> System.Collections.Generic.IList<object?>!
Microsoft.AspNetCore.Http.RouteHandlerInvocationContext.RouteHandlerInvocationContext(Microsoft.AspNetCore.Http.HttpContext! httpContext, params object![]! parameters) -> void
Microsoft.AspNetCore.Routing.RouteValueDictionary.RouteValueDictionary(Microsoft.AspNetCore.Routing.RouteValueDictionary? dictionary) -> void
Microsoft.AspNetCore.Routing.RouteValueDictionary.RouteValueDictionary(System.Collections.Generic.IEnumerable<System.Collections.Generic.KeyValuePair<string!, object?>>? values) -> void
Expand All @@ -27,3 +25,6 @@ Microsoft.AspNetCore.Http.Metadata.IEndpointDescriptionMetadata
Microsoft.AspNetCore.Http.Metadata.IEndpointDescriptionMetadata.Description.get -> string!
Microsoft.AspNetCore.Http.Metadata.IEndpointSummaryMetadata
Microsoft.AspNetCore.Http.Metadata.IEndpointSummaryMetadata.Summary.get -> string!
virtual Microsoft.AspNetCore.Http.RouteHandlerInvocationContext.GetParameter<T>(int index) -> T
virtual Microsoft.AspNetCore.Http.RouteHandlerInvocationContext.HttpContext.get -> Microsoft.AspNetCore.Http.HttpContext!
virtual Microsoft.AspNetCore.Http.RouteHandlerInvocationContext.Parameters.get -> System.Collections.Generic.IList<object?>!
24 changes: 21 additions & 3 deletions src/Http/Http.Abstractions/src/RouteHandlerInvocationContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,15 @@ namespace Microsoft.AspNetCore.Http;
/// Provides an abstraction for wrapping the <see cref="HttpContext"/> and parameters
/// provided to a route handler.
/// </summary>
public sealed class RouteHandlerInvocationContext
public class RouteHandlerInvocationContext
{
#pragma warning disable CS8618 // Non-nullable field must contain a non-null value when exiting constructor. Consider declaring as nullable.
// Provide an internal parameterless constructor for RHIC so that child classes
// can instantiate their instances without having to instantiate this base class
// and allocate an object[]
internal RouteHandlerInvocationContext() { }
#pragma warning restore CS8618 // Non-nullable field must contain a non-null value when exiting constructor. Consider declaring as nullable.

/// <summary>
/// Creates a new instance of the <see cref="RouteHandlerInvocationContext"/> for a given request.
/// </summary>
Expand All @@ -23,13 +30,24 @@ public RouteHandlerInvocationContext(HttpContext httpContext, params object[] pa
/// <summary>
/// The <see cref="HttpContext"/> associated with the current request being processed by the filter.
/// </summary>
public HttpContext HttpContext { get; }
public virtual HttpContext HttpContext { get; }

/// <summary>
/// A list of parameters provided in the current request to the filter.
/// <remarks>
/// This list is not read-only to permit modifying of existing parameters by filters.
/// </remarks>
/// </summary>
public IList<object?> Parameters { get; }
public virtual IList<object?> Parameters { get; }

/// <summary>
/// Retrieve the parameter given its position in the argument list.
/// </summary>
/// <typeparam name="T">The <see cref="Type"/> of the resolved parameter.</typeparam>
/// <param name="index">An integer representing the position of the parameter in the argument list.</param>
/// <returns>The parameter at a given <paramref name="index"/></returns>
public virtual T GetParameter<T>(int index)
{
return (T)Parameters[index]!;
}
}
Loading