ardalis/Result

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

Open

#175 aperta il 10 apr 2024

Vedi su GitHub
 (2 commenti) (2 reazioni) (0 assegnatari)C# (126 fork)github user discovery
enhancementgood first issuehelp wanted

Metriche repository

Star
 (1034 star)
Metriche merge PR
 (Metriche PR in attesa)

Descrizione

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);
}

Guida contributor