-
Notifications
You must be signed in to change notification settings - Fork 10.4k
Add new Use middleware extension method #31784
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
Conversation
Is this a breaking change? |
/// { | ||
/// return next(context); | ||
/// }); | ||
/// </code> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you also add a quip about preferring Run
if next
is unused?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
I'm curious to get this into a preview and see if we get any feedback about it. People will only notice it on re-compile, and I wonder how obvious it will be if they need to switch to Run. |
This should be in for preview4 if we're going to do it. |
a34b163
to
4332107
Compare
Hello human! Please make sure you've included the Shiproom Template in a comment or (preferably) the PR description. Also, make sure this PR is not marked as a draft and is ready-to-merge. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like it, and I think we should do this for preview4. I'm not sure the risk is "low" though. This breaking change broke a couple samples and a lot of tests that were using Use
instead of Run
for terminal middleware, right? I don't think it's that uncommon of a pattern.
This is at least "medium" risk, right?
I see risk as more of "possibility of breaking your applications behavior unexpectedly". This wont break your apps behavior, you might just need to modify your code slightly to compile. |
So compile-time breaking changes that don't change runtime behavior of apps that still compile without changes are considered "low" risk? And the number existing apps that work in .NET 5 and won't compile after this change has absolutely no impact on the risk? I guess I can get behind that for previews since we can always revert and there's a simple code fix. I'm just surprised that's the standard. |
I mean, that's my opinion, not a standard. And risk in this case doesn't mean the same thing as it does for patches and RC releases. If we were making a compile time breaking change in a patch, then this would be Extremely high risk. But like you noted, since this is a preview and we can revert it later, low risk. |
Yes. What does the compile error look like exactly BTW? |
|
/azp run |
Azure Pipelines successfully started running 1 pipeline(s). |
@dotnet/aspnet-build |
|
Hi @Rick-Anderson. It looks like you just commented on a closed PR. The team will most probably miss it. If you'd like to bring something important up to their attention, consider filing a new issue and add enough details to build context. |
Description
Add a new
app.Use
overload that requires users to pass theHttpContext
to thenext
function which will save 2 per-request allocations over the previous extension method.Customer Impact
Less per-request allocations when using simple middleware.
Regression?
Risk
[Justify the selection above]
Terminal middleware that used
app.Use
will need to update to useapp.Run
otherwise they'll get an ambiguous method compile error. We'd like to get this in early to get feedback on how bad that is, or if it isn't a problem.Verification
Packaging changes reviewed?
Fixes #31463
Main change is located at https://github.com/dotnet/aspnetcore/compare/brecon/use?expand=1#diff-e80bc3e234b6da05aea986e2aaa5b92bf492f085e00e7497d268e107169c9c6c
and
https://github.com/dotnet/aspnetcore/compare/brecon/use?expand=1#diff-dcc7a146ff62319dc1f9ab1847a9697596a4d899e7f75b588ed3c74d594ea305
The rest is changing all our tests and samples to use the new overload, or switch to
app.Run
if they never callednext
.Should we file a breaking change announcement that people calling
app.Use
without callingnext
will be broken?Note: We should apply this same change to the
ConnectionBuilder
aspnetcore/src/Servers/Connections.Abstractions/src/ConnectionBuilderExtensions.cs
Line 42 in 686da2e
TODO: File docs issue to update code to use new overload