ardalis/Result
Consider New Ardalis.Result.FastEndpoints package with base classes, extension methods
開放
#175 建立於 2024年4月10日
enhancementgood first issuehelp wanted
倉庫指標
- 星標
- (1,034 顆星)
- PR 合併指標
- (平均合併 8天 3小時) (30 天內合併 2 個 PR)
描述
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);
}