Add new Use middleware extension method by BrennanConroy · Pull Request #31784 · dotnet/aspnetcore (original) (raw)
Description
Add a new app.Use
overload that requires users to pass the HttpContext
to the next
function which will save 2 per-request allocations over the previous extension method.
Customer Impact
Less per-request allocations when using simple middleware.
Regression?
- Yes
- No
Risk
- High
- Medium
- Low
[Justify the selection above]
Terminal middleware that used app.Use
will need to update to use app.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
- Manual (required)
- Automated
Packaging changes reviewed?
- Yes
- No
- N/A
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 called next
.
Should we file a breaking change announcement that people calling app.Use
without calling next
will be broken?
Note: We should apply this same change to the ConnectionBuilder
aspnetcore/src/Servers/Connections.Abstractions/src/ConnectionBuilderExtensions.cs
Line 42 in686da2e
Func<Task> simpleNext = () => next(context); |
---|
TODO: File docs issue to update code to use new overload