Refactor action behaviors to use Unit instead of bool
Refactored PreprocessingBehavior and PostprocessingBehavior for InvokeRecActionViewCommand to use MediatR's Unit as the response type instead of bool. Updated method signatures, return values, and DI registration accordingly to align with MediatR conventions for commands without return values.
This commit is contained in:
@@ -7,19 +7,18 @@ using System.Text.Json;
|
|||||||
|
|
||||||
namespace ReC.Application.Common.Behaviors.Action;
|
namespace ReC.Application.Common.Behaviors.Action;
|
||||||
|
|
||||||
public class PostprocessingBehavior(IRecDbContext context, ISender sender) : IPipelineBehavior<InvokeRecActionViewCommand, bool>
|
public class PostprocessingBehavior(IRecDbContext context, ISender sender) : IPipelineBehavior<InvokeRecActionViewCommand, Unit>
|
||||||
{
|
{
|
||||||
public async Task<bool> Handle(InvokeRecActionViewCommand request, RequestHandlerDelegate<bool> next, CancellationToken cancel)
|
public async Task<Unit> Handle(InvokeRecActionViewCommand request, RequestHandlerDelegate<Unit> next, CancellationToken cancel)
|
||||||
{
|
{
|
||||||
var response = false;
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
response = await next(cancel);
|
await next(cancel);
|
||||||
}
|
}
|
||||||
catch
|
catch
|
||||||
{
|
{
|
||||||
if (request.Action.ErrorAction == ErrorAction.Stop)
|
if (request.Action.ErrorAction == ErrorAction.Stop)
|
||||||
return false;
|
return Unit.Value;
|
||||||
}
|
}
|
||||||
|
|
||||||
string? info = null, error = null;
|
string? info = null, error = null;
|
||||||
@@ -44,6 +43,6 @@ public class PostprocessingBehavior(IRecDbContext context, ISender sender) : IPi
|
|||||||
Error = error
|
Error = error
|
||||||
}, cancel);
|
}, cancel);
|
||||||
|
|
||||||
return response;
|
return Unit.Value;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -7,9 +7,9 @@ using System.Text.Json;
|
|||||||
|
|
||||||
namespace ReC.Application.Common.Behaviors.Action;
|
namespace ReC.Application.Common.Behaviors.Action;
|
||||||
|
|
||||||
public class PreprocessingBehavior(IRecDbContext context, ISender sender) : IPipelineBehavior<InvokeRecActionViewCommand, bool>
|
public class PreprocessingBehavior(IRecDbContext context, ISender sender) : IPipelineBehavior<InvokeRecActionViewCommand, Unit>
|
||||||
{
|
{
|
||||||
public async Task<bool> Handle(InvokeRecActionViewCommand request, RequestHandlerDelegate<bool> next, CancellationToken cancel)
|
public async Task<Unit> Handle(InvokeRecActionViewCommand request, RequestHandlerDelegate<Unit> next, CancellationToken cancel)
|
||||||
{
|
{
|
||||||
string? info = null, error = null;
|
string? info = null, error = null;
|
||||||
|
|
||||||
@@ -34,7 +34,7 @@ public class PreprocessingBehavior(IRecDbContext context, ISender sender) : IPip
|
|||||||
}, cancel);
|
}, cancel);
|
||||||
|
|
||||||
if (error is not null && request.Action.ErrorAction == ErrorAction.Stop)
|
if (error is not null && request.Action.ErrorAction == ErrorAction.Stop)
|
||||||
return false;
|
return Unit.Value;
|
||||||
|
|
||||||
return await next(cancel);
|
return await next(cancel);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -35,8 +35,8 @@ public static class DependencyInjection
|
|||||||
cfg.RegisterServicesFromAssembly(Assembly.GetExecutingAssembly());
|
cfg.RegisterServicesFromAssembly(Assembly.GetExecutingAssembly());
|
||||||
cfg.AddOpenBehaviors([typeof(BodyQueryBehavior<,>), typeof(HeaderQueryBehavior<,>)]);
|
cfg.AddOpenBehaviors([typeof(BodyQueryBehavior<,>), typeof(HeaderQueryBehavior<,>)]);
|
||||||
cfg.AddBehavior(typeof(IPipelineBehavior<,>), typeof(ValidationBehavior<,>));
|
cfg.AddBehavior(typeof(IPipelineBehavior<,>), typeof(ValidationBehavior<,>));
|
||||||
cfg.AddBehavior(typeof(IPipelineBehavior<InvokeRecActionViewCommand, bool>), typeof(PostprocessingBehavior));
|
cfg.AddBehavior(typeof(IPipelineBehavior<InvokeRecActionViewCommand, Unit>), typeof(PostprocessingBehavior));
|
||||||
cfg.AddBehavior(typeof(IPipelineBehavior<InvokeRecActionViewCommand, bool>), typeof(PreprocessingBehavior));
|
cfg.AddBehavior(typeof(IPipelineBehavior<InvokeRecActionViewCommand, Unit>), typeof(PreprocessingBehavior));
|
||||||
cfg.LicenseKey = configOpt.LuckyPennySoftwareLicenseKey;
|
cfg.LicenseKey = configOpt.LuckyPennySoftwareLicenseKey;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user