Skip to content
This repository was archived by the owner on Apr 17, 2025. It is now read-only.

Commit b53f697

Browse files
committed
Implementazione validazione con FluentValidation (closes #21)
1 parent 5770b83 commit b53f697

File tree

3 files changed

+29
-1
lines changed

3 files changed

+29
-1
lines changed

src/NET6CustomLibrary/GlobalUsings.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
global using System.Text.Json.Serialization;
1111
global using System.Threading;
1212
global using System.Threading.Tasks;
13+
global using FluentValidation.Results;
1314
global using MailKit.Net.Smtp;
1415
global using MailKit.Security;
1516
global using MediatR;
@@ -47,7 +48,7 @@
4748
global using NET6CustomLibrary.RedisCache.Services;
4849
global using NET6CustomLibrary.Serilog.Models;
4950
global using NET6CustomLibrary.Serilog.Services;
50-
//global using NET6CustomLibrary.Validazione.Interfaces;
51+
global using NET6CustomLibrary.Validazione.Interfaces;
5152
global using Npgsql;
5253
global using RabbitMQ.Client;
5354
global using RabbitMQ.Client.Events;
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
namespace NET6CustomLibrary.Validazione.Interfaces;
2+
3+
public interface IValidation
4+
{
5+
List<string> ProcessErrorList(ValidationResult validationResult);
6+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
namespace NET6CustomLibrary.Validazione;
2+
3+
public class Validation : IValidation
4+
{
5+
private readonly ILoggerService logger;
6+
7+
public Validation(ILoggerService logger)
8+
{
9+
this.logger = logger;
10+
}
11+
12+
public List<string> ProcessErrorList(ValidationResult validationResult)
13+
{
14+
List<string> errorList = new();
15+
16+
validationResult.Errors.ForEach(x => errorList.Add(x.ErrorMessage));
17+
validationResult.Errors.ForEach(y => logger.SaveLogError(y.ErrorMessage));
18+
19+
return errorList;
20+
}
21+
}

0 commit comments

Comments
 (0)