Add PreprocessingBehavior for action command pipeline

Introduced PreprocessingBehavior implementing MediatR's IPipelineBehavior for InvokeRecActionViewCommand. This behavior executes a preprocessing SQL query if specified, and halts processing if an error occurs and ErrorAction is set to Stop. Added necessary using directives for dependencies.
This commit is contained in:
2026-03-24 11:14:11 +01:00
parent 4f0f99e0f8
commit 3e10176d98

View File

@@ -0,0 +1,29 @@
using DigitalData.Core.Abstraction.Application.Repository;
using MediatR;
using ReC.Application.Common.Interfaces;
using ReC.Application.RecActions.Commands;
using ReC.Domain.Constants;
namespace ReC.Application.Common.Behaviors.Action;
public class PreprocessingBehavior(IRecDbContext context, ISender sender) : IPipelineBehavior<InvokeRecActionViewCommand, bool>
{
public async Task<bool> Handle(InvokeRecActionViewCommand request, RequestHandlerDelegate<bool> next, CancellationToken cancel)
{
try
{
if (request.Action.PreprocessingQuery is string query)
await context.ExecuteDynamicSqlAsync(query);
}
catch (Exception ex)
{
if(request.Action.ErrorAction == ErrorAction.Stop)
{
// save output result
return false;
}
}
return await next(cancel);
}
}