aspnet / HttpAbstractions

[Archived] HTTP abstractions such as HttpRequest, HttpResponse, and HttpContext, as well as common web utilities. Project moved to https://github.com/aspnet/AspNetCore
Apache License 2.0
382 stars 194 forks source link

Use object indirection in HttpContextAccessor #1066

Closed benaadams closed 5 years ago

benaadams commented 5 years ago

Use an extra level of indirection in HttpContextAccessor so what is being held onto is shared (rather than its own reference); so when the request is done that second indirection can be cleared for everything holding on to HttpContextHolder at which point it will remain inert and they won't see data for the next request (as a new HttpContextHolder will be created)

davidfowl commented 5 years ago

Change the HttpContextFactory to not set the TraceIdentifier to null. Also tweak some of these tests https://github.com/aspnet/HttpAbstractions/pull/1021/files to avoid the TraceIdentifier comparison

davidfowl commented 5 years ago

It's an extra allocation per request but async locals aren't super light anyways so this is fine.