-
Notifications
You must be signed in to change notification settings - Fork 10k
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
Feature/httpendpoint #57565
base: main
Are you sure you want to change the base?
Feature/httpendpoint #57565
Conversation
This reverts commit 9e03369.
src/Http/Http.Abstractions/src/Routing/EndpointHttpContextExtensions.cs
Outdated
Show resolved
Hide resolved
src/Http/Http.Abstractions/src/Routing/EndpointHttpContextExtensions.cs
Outdated
Show resolved
Hide resolved
Co-authored-by: Günther Foidl <gue@korporal.at>
Co-authored-by: Günther Foidl <gue@korporal.at>
Co-authored-by: Günther Foidl <gue@korporal.at>
…nsions.cs Co-authored-by: Günther Foidl <gue@korporal.at>
ATM there are build errors, as the public API changes, but there's no entry for that change. So please follow along How to use Microsoft.CodeAnalysis.PublicApiAnalyzers to fix the build erros. |
@dotnet-policy-service agree company="Retro Rabbit" |
Just noticed that this is a draft. Feel free to ignore my comments if they don't make sense yet. |
@Phumi-codes Thanks for opening this issue! Since this pull request introduces API changes, the associated issue will need to undergo API review first before we can merge this. |
Thank you for the update! Just to clarify, will the API review be conducted by the team, or is there anything specific I need to do to help initiate or prepare for the review? Please let me know if there's anything further required from my side. Thanks! |
The team usually review new APIs weekly. |
Add HttpContext.Endpoint property
Overview of the Problem
The goal was to introduce an Endpoint property directly on the HttpContext class. This change aims to make endpoint handling more intuitive and seamless, improving the developer experience by avoiding the need for extension methods like GetEndpoint and SetEndpoint.
Description
Changes to the HttpContext Class
New Endpoint Property:
Justification: Adding Endpoint as a direct property on HttpContext allows for more straightforward access to the current endpoint associated with the request. This change enhances usability and aligns with the way other intrinsic properties (like Request, Response) are accessed.
Details: The Endpoint property uses the existing feature collection to fetch or initialize an IEndpointFeature instance, which stores the current endpoint.
Modifications to the DefaultHttpContext Class
Implementation of Endpoint Property:
Getter: Retrieves the Endpoint from the IEndpointFeature. If the feature doesn't exist, it initializes a new EndpointFeature instance.
Setter: Sets the Endpoint on the IEndpointFeature. If the endpoint is null, it resets the feature accordingly.
Justification: This approach maintains backward compatibility, as the existing feature mechanism is preserved. It ensures that endpoints are handled uniformly across different contexts and allows for easy future extensions.
Removal of the SetEndpoint Method from EndpointHttpContextExtensions
Justification: With the Endpoint property now directly on HttpContext, the SetEndpoint method in the EndpointHttpContextExtensions class became redundant. Removing it reduces code duplication and potential confusion.
Adjustments to Unit Tests
Updated Test Cases:
Justification: The test cases were modified to align with the new Endpoint property implementation. Previously, the tests relied on the SetEndpoint method, but now they test the direct interaction with the Endpoint property.
Details: The test ensuring that no IEndpointFeature is set on a context without a feature has been adjusted. Now, it verifies that an EndpointFeature is always created if accessed, even if the endpoint is set to null.
Any feedback would be appreciated
Fixes #50522