From 2bfa2acbd2ae27ee677215eee4c63722619a22ba Mon Sep 17 00:00:00 2001 From: "Jeremy D. Miller" Date: Fri, 15 Sep 2023 14:59:17 -0500 Subject: [PATCH] Running FluentValidation validators single file to dodge concurrency problems. Closes GH-537 --- .../Internals/FluentValidationExecutor.cs | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/src/Extensions/Wolverine.FluentValidation/Internals/FluentValidationExecutor.cs b/src/Extensions/Wolverine.FluentValidation/Internals/FluentValidationExecutor.cs index 8248d3436..136c354d5 100644 --- a/src/Extensions/Wolverine.FluentValidation/Internals/FluentValidationExecutor.cs +++ b/src/Extensions/Wolverine.FluentValidation/Internals/FluentValidationExecutor.cs @@ -1,5 +1,6 @@ using System.Runtime.CompilerServices; using FluentValidation; +using FluentValidation.Results; namespace Wolverine.FluentValidation.Internals; @@ -19,16 +20,21 @@ public static async Task ExecuteOne(IValidator validator, IFailureAction(IReadOnlyList> validators, IFailureAction failureAction, T message) { - var validationFailureTasks = validators - .Select(validator => validator.ValidateAsync(message)); - var validationFailures = await Task.WhenAll(validationFailureTasks); - var failures = validationFailures.SelectMany(validationResult => validationResult.Errors) - .Where(validationFailure => validationFailure != null) - .ToList(); + var failures = new List(); + foreach (var validator in validators) + { + var result = await validator.ValidateAsync(message); + if (result is not null && result.Errors.Any()) + { + failures.AddRange(result.Errors); + } + } + if (failures.Any()) { failureAction.Throw(message, failures); } } + } \ No newline at end of file