Add AuthScopedValidator and register FluentValidation
Introduced AuthScopedValidator to enforce non-empty AddedWho on IAuthScoped entities with a clear error message. Registered all validators from the assembly in DI to enable automatic validation for authentication-scoped entities.
This commit is contained in:
@@ -0,0 +1,14 @@
|
|||||||
|
using FluentValidation;
|
||||||
|
using ReC.Application.Common.Interfaces;
|
||||||
|
|
||||||
|
namespace ReC.Application.Common.Validations;
|
||||||
|
|
||||||
|
public class AuthScopedValidator : AbstractValidator<IAuthScoped>
|
||||||
|
{
|
||||||
|
public AuthScopedValidator()
|
||||||
|
{
|
||||||
|
RuleFor(x => x.AddedWho)
|
||||||
|
.NotEmpty()
|
||||||
|
.WithMessage("The 'AddedWho' field is required. A missing value may indicate an API configuration issue. Please contact your system administrator for assistance.");
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,7 +1,9 @@
|
|||||||
using DigitalData.Core.Infrastructure;
|
using DigitalData.Core.Infrastructure;
|
||||||
|
using FluentValidation;
|
||||||
using Microsoft.EntityFrameworkCore;
|
using Microsoft.EntityFrameworkCore;
|
||||||
using Microsoft.Extensions.DependencyInjection;
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
using ReC.Application.Common.Interfaces;
|
using ReC.Application.Common.Interfaces;
|
||||||
|
using ReC.Application.Common.Validations;
|
||||||
using ReC.Domain.Entities;
|
using ReC.Domain.Entities;
|
||||||
|
|
||||||
namespace ReC.Infrastructure;
|
namespace ReC.Infrastructure;
|
||||||
@@ -23,6 +25,8 @@ public static class DependencyInjection
|
|||||||
|
|
||||||
services.AddDbRepository(opt => opt.RegisterFromAssembly<TRecDbContext>(typeof(RecActionView).Assembly));
|
services.AddDbRepository(opt => opt.RegisterFromAssembly<TRecDbContext>(typeof(RecActionView).Assembly));
|
||||||
|
|
||||||
|
services.AddValidatorsFromAssembly(typeof(AuthScopedValidator).Assembly);
|
||||||
|
|
||||||
return services;
|
return services;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user