-
Notifications
You must be signed in to change notification settings - Fork 10.3k
seal DefaultHttpContext and remove obsolete members #6504
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
Question from someone not super familiar with the internals of Http: What is the reason for choosing to make public sealed class ReusableHttpContext : DefaultHttpContext { } There would be overhead ensuring changes to DefaultHttpContext are then made reusable in ReusableHttpContext, but it would avoid the breaking change. Sealing could break a lot of test code based around mocking, e.g. |
More overhead, more fields, more virtual calls. The fields inside of
Yes, that's the biggest risk in this change. Test code trying to override members of DefaultHttpContext without using features. |
So you're planning on deleting ReusableHttpContext and going back to using DefaultHttpContext? |
Ok! A mitigation could be to have something like |
Yes, that's a decent mitigation as well. |
If you're using Moq anyway, what's wrong with It's also a little unfortunate that DefaultHttpContext.(Un)Initialize() is still public now that it's no longer virtual. Is there any reason a developer should ever call these instead of letting the server handle the pooling? |
It should never be called by the end user but they are given an HttpContext anyways, they would need to downcast to even see these methods. |
@halter73 The difference is Some results for mocking the default context, but less than I would have guessed: https://github.com/search?q=%22Mock%3CDefaultHttpContext%3E%22&type=Code - 10 results |
3bdf03b
to
f08e8c9
Compare
|
Make the break 😍 Is a Alternative would be to make the changes to |
In N years of building MVC core, I haven't happened upon a situation where mocking the context is a better choice than newing up a |
Most of the tests I see, new up the DefaultHttpContext (it was actually intentional to make it POCO like and newable). A few purists mock the HttpContext and 10 people on github mock the DefaultHttpContext. I'm sure even less have a derived type outside of that last scenario besides @benaadams. If it's too big of a break, we can unseal the DefaultHttpContext but we'd likely be missing out on some JIT optimizations (though TBH I'm not 100% sure if there are other things preventing that from happening). |
8dfee5e
to
26164d0
Compare
- Seal all of the classes - Remove virtual methods - Delete pooled HttpContext code - Removed obsolete AuthenticationManager
26164d0
to
744be8c
Compare
So I'm guessing @DamianEdwards is going to have to sign off on this one, or @Eilon |
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.
Breaking change approved at this stage given the data and discussed potential mitigations we could employ later on.
Is this announcement-worthy? |
I can rebase my PR after |
I won't miss it; only do it for pooling, but its way over designed for that. If it becomes both faster and pooled as part of the baseline, my use case (and I imagine anyone else's) has gone and is served by the base framework. |
Spoke to @DamianEdwards offline about this breaking change so putting it here in a PR to review. I'm sure I need to update other things as well but this is the baseline. Motivation for this change comes from this PR #6424
PS: There are a class of other changes related to the DefaultHttpContext that we want to optimize:
aspnet/HttpAbstractions#999
cc @benaadams