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:
2025-12-03 15:00:56 +01:00
parent b3ce5ad28a
commit cd53d7fbae
4 changed files with 51 additions and 1 deletions

View File

@@ -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;
});