Add validation pipeline with FluentValidation and MediatR
Introduced a validation pipeline using FluentValidation and MediatR to enhance request validation. Added the following: - Registered FluentValidation and MediatR dependencies in `ReC.Application.csproj`. - Updated `DependencyInjection.cs` to register validators and MediatR behaviors, including `ValidationBehavior<,>`. - Added `ValidationBehavior<TRequest, TResponse>` to handle request validation in the MediatR pipeline. - Created `ReadOutResQueryValidator` to enforce validation rules for `ReadOutResQuery`. - Refactored namespaces and imports for better organization. These changes improve extensibility, maintainability, and separation of concerns in the application.
This commit is contained in:
@@ -1,8 +1,10 @@
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using MediatR;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using ReC.Application.Common.Behaviors;
|
||||
using ReC.Application.Common.Options;
|
||||
using System.Reflection;
|
||||
using FluentValidation;
|
||||
|
||||
namespace ReC.Application;
|
||||
|
||||
@@ -17,6 +19,8 @@ public static class DependencyInjection
|
||||
|
||||
configOpt.ApplyConfigurations(services);
|
||||
|
||||
services.AddValidatorsFromAssembly(Assembly.GetExecutingAssembly());
|
||||
|
||||
services.AddAutoMapper(cfg =>
|
||||
{
|
||||
cfg.AddMaps(Assembly.GetExecutingAssembly());
|
||||
@@ -27,6 +31,7 @@ public static class DependencyInjection
|
||||
{
|
||||
cfg.RegisterServicesFromAssembly(Assembly.GetExecutingAssembly());
|
||||
cfg.AddOpenBehaviors([typeof(BodyQueryBehavior<,>), typeof(HeaderQueryBehavior<,>)]);
|
||||
cfg.AddBehavior(typeof(IPipelineBehavior<,>), typeof(ValidationBehavior<,>));
|
||||
cfg.LicenseKey = configOpt.LuckyPennySoftwareLicenseKey;
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user