EmptyHttpResult is not straightforward to be used in type checking #45063
Labels
old-area-web-frameworks-do-not-use
*DEPRECATED* This label is deprecated in favor of the area-mvc and area-minimal labels
Milestone
Is there an existing issue for this?
Is your feature request related to a problem? Please describe the problem.
I created a generic endpoint filter
which has the purpose to log the request and response objects of an endpoint.
As a side note, I know that .NET 7 offers some similar functionality but it's not good enough for my needs (because it doesn't allow me to mark sensitive properties on the request/response object and filter them).
I made some extension methods to simplify the registration of the endpoint filter:
and I use them to register the filter on some endpoints:
Inside the filter I have this logic:
As you can see, I am also doing some validations and type checking to make let the developer know that the type he registered on the endpoint filter is not the same as the actual object type.
The
EmptyHttpRequest
is a record I created to represent the situation when an endpoint doesn't have a request object.The
EmptyHttpResult
is what I saw that the framework returns on the response when the endpoint has no response (e.g.: "myEndpointWithNoResponse"). So when I have an endpoint with no response I register the filter like thisbuilder.AddEndpointFilter<EndpointRequestResponseLoggingFilter<TRequest, EmptyHttpResult>>()
The problem though is that I have to do the comparison like this:
if (response.GetType().Name is nameof(EmptyHttpResult))
because the public typed exposed by the framework isMicrosoft.AspNetCore.Http.HttpResults.EmptyHttpResult
while the type of the response object isMicrosoft.AspNetCore.Http.RequestDelegateFactory+EmptyHttpResult
.Describe the solution you'd like
I would like the response object to have the type
Microsoft.AspNetCore.Http.HttpResults.EmptyHttpResult
so I can do the comparison in a much simpler way:if (response is EmptyHttpResult)
.Additional context
I am using the dotnet version: 7.0.100
The text was updated successfully, but these errors were encountered: