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:
@@ -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);
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user