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

Consider New Ardalis.Result.FastEndpoints package with base classes, extension methods #175

Open
ardalis opened this issue Apr 10, 2024 · 2 comments
Labels
enhancement New feature or request good first issue Good for newcomers help wanted Extra attention is needed

Comments

@ardalis
Copy link
Owner

ardalis commented Apr 10, 2024

For example this code from a devBetter.com member:

public abstract class EndpointBase<TRequest, TResponse, TMapper> : Endpoint<TRequest, IResult, TMapper> where TRequest : notnull where TResponse : notnull where TMapper : class, IResponseMapper
{
    public override async Task<IResult> ExecuteAsync(TRequest req, CancellationToken ct)
    {
        Result<TResponse> response = await ProcessAsync(req, ct)
            .ConfigureAwait(false);

        this.AddResultErrors(response);

        ThrowIfAnyErrors();

        return response
            .ToMinimalApiResult();
    }

    public abstract Task<Result<TResponse>> ProcessAsync(TRequest request, CancellationToken cancellationToken);
}

// or similar by nhwilly
public abstract class EndpointBase<TRequest, TResponse> : Endpoint<TRequest, Microsoft.AspNetCore.Http.IResult> where TRequest : notnull where TResponse : notnull
{
  public override async Task<Microsoft.AspNetCore.Http.IResult> ExecuteAsync(TRequest req, CancellationToken ct)
  {
    Result<TResponse> response = await ProcessAsync(req, ct)
        .ConfigureAwait(false);

    this.AddResultErrors(response);

    ThrowIfAnyErrors();

    return response.ToMinimalApiResult();
  }

  public abstract Task<Result<TResponse>> ProcessAsync(TRequest request, CancellationToken cancellationToken);
}
@ardalis ardalis added the enhancement New feature or request label Apr 10, 2024
@KyleMcMaster
Copy link
Collaborator

See: #157

@nhwilly
Copy link

nhwilly commented Apr 12, 2024

I tried that, but quickly ran into limitations for 201 and we'd have to subclass other varieties, for no dto returned, etc. I backed off until I have more time later.

See #174

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request good first issue Good for newcomers help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

3 participants