chore: rename internal types
Rename internal types in the validation to be more consistent with other projects
This commit is contained in:
parent
36f1a9eb1b
commit
c674de31f7
2 changed files with 35 additions and 31 deletions
|
|
@ -4,14 +4,11 @@
|
||||||
using System.Collections.Concurrent;
|
using System.Collections.Concurrent;
|
||||||
using System.Reflection.Metadata;
|
using System.Reflection.Metadata;
|
||||||
|
|
||||||
using Microsoft.Extensions.DependencyInjection;
|
|
||||||
using Microsoft.Extensions.Options;
|
|
||||||
|
|
||||||
[assembly: MetadataUpdateHandler(typeof(Geekeey.Request.Validation.DispatchingValidator))]
|
[assembly: MetadataUpdateHandler(typeof(Geekeey.Request.Validation.DispatchingValidator))]
|
||||||
|
|
||||||
namespace Geekeey.Request.Validation;
|
namespace Geekeey.Request.Validation;
|
||||||
|
|
||||||
internal sealed class DispatchingValidator : IValidator
|
internal sealed partial class DispatchingValidator : IValidator
|
||||||
{
|
{
|
||||||
private static readonly ConcurrentDictionary<Type, ValidatorInvoker> ValidatorsHandlers = new();
|
private static readonly ConcurrentDictionary<Type, ValidatorInvoker> ValidatorsHandlers = new();
|
||||||
|
|
||||||
|
|
@ -44,31 +41,4 @@ internal sealed class DispatchingValidator : IValidator
|
||||||
|
|
||||||
return handler.Validate(context, _serviceProvider);
|
return handler.Validate(context, _serviceProvider);
|
||||||
}
|
}
|
||||||
|
|
||||||
private abstract class ValidatorInvoker
|
|
||||||
{
|
|
||||||
public abstract Validation Validate(ValidationContext context, IServiceProvider serviceProvider);
|
|
||||||
}
|
|
||||||
|
|
||||||
private sealed class ValidatorInvoker<T> : ValidatorInvoker
|
|
||||||
{
|
|
||||||
public override Validation Validate(ValidationContext context, IServiceProvider serviceProvider)
|
|
||||||
{
|
|
||||||
var options = serviceProvider.GetRequiredService<IOptions<RequestValidatorOptions>>().Value;
|
|
||||||
|
|
||||||
var validators = options.GetValidators<T>(serviceProvider);
|
|
||||||
|
|
||||||
var problems = new List<Problem>();
|
|
||||||
|
|
||||||
foreach (var validator in validators)
|
|
||||||
{
|
|
||||||
if (validator.Validate(context) is { IsValid: false, Problems: { } result })
|
|
||||||
{
|
|
||||||
problems.AddRange(result);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return new Validation(problems);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
34
src/request.validation/ValidatorInvoker.cs
Normal file
34
src/request.validation/ValidatorInvoker.cs
Normal file
|
|
@ -0,0 +1,34 @@
|
||||||
|
// Copyright (c) The Geekeey Authors
|
||||||
|
// SPDX-License-Identifier: EUPL-1.2
|
||||||
|
|
||||||
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
|
using Microsoft.Extensions.Options;
|
||||||
|
|
||||||
|
namespace Geekeey.Request.Validation;
|
||||||
|
|
||||||
|
internal abstract class ValidatorInvoker
|
||||||
|
{
|
||||||
|
public abstract Validation Validate(ValidationContext context, IServiceProvider serviceProvider);
|
||||||
|
}
|
||||||
|
|
||||||
|
internal sealed class ValidatorInvoker<T> : ValidatorInvoker
|
||||||
|
{
|
||||||
|
public override Validation Validate(ValidationContext context, IServiceProvider serviceProvider)
|
||||||
|
{
|
||||||
|
var options = serviceProvider.GetRequiredService<IOptions<RequestValidatorOptions>>().Value;
|
||||||
|
|
||||||
|
var validators = options.GetValidators<T>(serviceProvider);
|
||||||
|
|
||||||
|
var problems = new List<Problem>();
|
||||||
|
|
||||||
|
foreach (var validator in validators)
|
||||||
|
{
|
||||||
|
if (validator.Validate(context) is { IsValid: false, Problems: { } result })
|
||||||
|
{
|
||||||
|
problems.AddRange(result);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return new Validation(problems);
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue