Add support for RouteHandlerInvocationContext<> overloads#41406
Conversation
|
Where are the object[] allocations coming from? |
The ~1000 allocations before the change are from the object's array initialized in the invocation pipeline when we do the boxing. The rest are more dispersed.
|
| public void ProhibitsActionsThatModifyListSize() | ||
| { | ||
| var context = new RouteHandlerInvocationContext<string, int, bool>(new DefaultHttpContext(), "This is a test", 42, false); | ||
| Assert.Throws<NotSupportedException>(() => context.Add("string")); |
There was a problem hiding this comment.
Given this, I think we should change the type of RouteHandlerInvocationContext.Arguments to IReadOnlyList<object?>.
There was a problem hiding this comment.
I don't think so.
The type we use for Arguments will be used in both the generic and non-generic overloads. For the non-generic overload, we have to use IList to support in-place modification of items in the list.
One option is that we could change the behavior of the implementation so that if you're using the non-generic variant (more than 10 arguments) you're not able to make modifications to parameters. For scenarios where you're using ten arguments or less, you'll be able to modify in-place using the custom setter in the generic overloads.
There was a problem hiding this comment.
Actually, nevermind. We cannot do this anyway. The IReadOnlyList implementation does not support a setter on this[index] so we would be able to use it for generic variants anways.
| </None> | ||
| </ItemGroup> | ||
|
|
||
| <ItemGroup> |
There was a problem hiding this comment.
I wonder if we can include this in the global directory.props
cc @dougbu
There was a problem hiding this comment.
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❔
There was a problem hiding this comment.
It's not an issue, I would just like to clean it up as we plan to code generate more things.
There was a problem hiding this comment.
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>
| @@ -0,0 +1,129 @@ | |||
| <#@ template language="C#" #> | |||
| <#@ output extension=".cs" #> | |||
|
🆙 📅 : Can I get another look at this? |
| /// Provides a default implementation for wrapping the <see cref="HttpContext"/> and parameters | ||
| /// provided to a route handler. | ||
| /// </summary> | ||
| public sealed class DefaultRouteHandlerInvocationContext : RouteHandlerInvocationContext |
There was a problem hiding this comment.
Was this name discussed/approved?
Closes #40514.
RouteHandlerInvocationContext<>overloads of various arity (supports up to 10 arguments)GetParameter<T>(int index)API toRouteHandlerInvocationContextHttpContextandParametersproperties onRouteHandlerInvocationContextvirtualAPI Changes
Perf Impact
Before:
Allocations for
System.Object[]in non-generic RHICAfter: