Skip to content

Difference between ValidationProblem method in Results and TypedResults classes #54553

Answered by vernou
McMlok asked this question in Q&A
Discussion options

You must be logged in to vote

When the result is of type that implement IResult, the response is generated by IResult.ExecuteAsync.

It's the case with ProblemHttpResult (that is returned by Results.ValidationProblem) and ValidationProblem (that is returned by TypedResults.ValidationProblem).

The method ProblemHttpResult.ExecuteAsync is :

public sealed class ProblemHttpResult : IResult, ...
{
    ...

    public async Task ExecuteAsync(HttpContext httpContext)
    {
        var problemDetailsService = httpContext.RequestServices.GetService<IProblemDetailsService>();
        if (problemDetailsService is null || !await problemDetailsService.TryWriteAsync(new() { HttpContext = httpContext, ProblemDetails = ProblemDetails }))

Replies: 2 comments 2 replies

Comment options

You must be logged in to vote
2 replies
@McMlok
Comment options

@vernou
Comment options

Answer selected by McMlok
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants