-
Notifications
You must be signed in to change notification settings - Fork 9.9k
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
Add HttpContext.Endpoint property #50522
Comments
cc @davidfowl |
Sounds reasonable to me |
How do we feel about removing the private EndpointFeature wrapper in addition to adding the public static Endpoint? GetEndpoint(this HttpContext context)
{
ArgumentNullException.ThrowIfNull(context);
return context.Features.Get<IEndpointFeature>()?.Endpoint;
}
public static void SetEndpoint(this HttpContext context, Endpoint? endpoint)
{
ArgumentNullException.ThrowIfNull(context);
var feature = context.Features.Get<IEndpointFeature>();
if (endpoint != null)
{
if (feature == null)
{
feature = new EndpointFeature();
context.Features.Set(feature);
...
}
private sealed class EndpointFeature : IEndpointFeature
{
public Endpoint? Endpoint { get; set; }
} Note, there currently seems to be an inconsistent pattern of accessing the endpoint value. The public extension methods Code relying on the presence of the EndpointFeature in the feature list of the HttpContext would experience bugs. If we want to avoid this, we may need to still maintain the endpoint value in the feature set within the concrete classes implementing HttpContext, or something similar to that effect. Refactoring the dependency on the Endpoint Feature wrapper is feasible but can break existing code. @JamesNK please let me know if I should proceed with removing the IEndpointFeature wrapper or what you advise, and I will create the PR. |
Is there an existing issue for this?
Is your feature request related to a problem? Please describe the problem.
ASP.NET Core includes the GetEndpoint and SetEndpoint extension methods for working with endpoints and HttpContext.
I think endpoints have become such an intrinsic feature to ASP.NET Core that we should consider making it a real property on
HttpContext
. A property would be easier to use (no need to have the right namespace for the extension method) and feel better to use compared to a method.Describe the solution you'd like
Add
HttpContext.Endpoint
property.Additional context
No response
The text was updated successfully, but these errors were encountered: