Skip to content
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

Using FastEndpoints Postprocessor and the SendResultAsync with .ToMinimalApiResult extension doesn't provide the filled "Result" in the context #221

Open
Kermel opened this issue Nov 16, 2024 · 0 comments

Comments

@Kermel
Copy link

Kermel commented Nov 16, 2024

I'm experimenting with FastEndpoints and I have an endpoint that finishes with the following call in the HandleAsync method:
Endpoint class:
internal class LoginEndpoint : Endpoint<LoginRequest, Result<LoginResponse>>

Handler method:

public override async Task HandleAsync(LoginRequest req, CancellationToken ct)
{
    var loginResponse = ...;
    ...//login response is of the Result<LoginResponse> type
    await SendResultAsync(loginResponse.ToMinimalApiResult());
}

Configure method:

public override void Configure()
{
    Verbs(Http.POST);
    Routes("/login");
    AllowAnonymous();
    PostProcessor<LoginPostProcessor>();
}

And the LoginPostProcessor:

internal class LoginPostProcessor : IPostProcessor<LoginRequest, Result<LoginResponse>>
{
    public async Task PostProcessAsync(IPostProcessorContext<LoginRequest, Result<LoginResponse>> context, CancellationToken ct)
    {
        if(context.Response?.Status == ResultStatus.Ok) // Login successful
        {
            //...do something
        }
    }
}

But the context.Response is null.

When I finish my Handler method just by this call:
await SendAsync(loginResponse, cancellation: ct);

then everything works....

Am I doing something wrong?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant