Refactor HeaderQueryBehavior for generic request/response

Updated HeaderQueryBehavior to support two generic type
parameters, TRequest and TResponse, for improved flexibility.
Replaced the single TRecAction type parameter and Unit return
type with a more generic implementation. Updated where
constraints to reflect the new generic types. Modified the
Handle method signature and logic to align with the updated
generic parameters.
This commit is contained in:
tekh 2025-12-03 10:16:29 +01:00
parent 0e62011f92
commit 4b0208ca56

View File

@ -7,10 +7,11 @@ using System.Text.Json;
namespace ReC.Application.Common.Behaviors;
public class HeaderQueryBehavior<TRecAction>(IRecDbContext dbContext, ILogger<HeaderQueryBehavior<TRecAction>>? logger = null) : IPipelineBehavior<TRecAction, Unit>
where TRecAction : RecActionDto
public class HeaderQueryBehavior<TRequest, TResponse>(IRecDbContext dbContext, ILogger<HeaderQueryBehavior<TRequest, TResponse>>? logger = null) : IPipelineBehavior<TRequest, TResponse>
where TRequest : RecActionDto
where TResponse : notnull
{
public async Task<Unit> Handle(TRecAction action, RequestHandlerDelegate<Unit> next, CancellationToken cancel)
public async Task<TResponse> Handle(TRequest action, RequestHandlerDelegate<TResponse> next, CancellationToken cancel)
{
if (action.HeaderQuery is null)
return await next(cancel);