mirror of
https://github.com/BinaryAlley/Nemera.git
synced 2026-12-03 14:11:10 +00:00
Replaces FluentValidation with the custom validation framework in the web project
This commit is contained in:
1 parent
587daaabb7
commit
57e8e2ed65
19 files changed
+1020
-104
No files matched your search
@@ -0,0 +1,30 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Presentation.Web.Common.Validation;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Options;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Presentation.Web.Common.Utilities;
|
||||
|
||||
/// <summary>
|
||||
/// Extension methods for adding configuration related options services to the DI container via <see cref="OptionsBuilder{TOptions}"/>.
|
||||
/// </summary>
|
||||
public static class OptionsBuilderValidationUtilities
|
||||
{
|
||||
/// <summary>
|
||||
/// Extension method to add validation to the options validation pipeline.
|
||||
/// </summary>
|
||||
/// <typeparam name="TOptions">The type of options being validated.</typeparam>
|
||||
/// <param name="optionsBuilder">The options builder to add the validation to.</param>
|
||||
/// <remarks>
|
||||
/// This method allows validating options of type <typeparamref name="TOptions"/> using a validator registered in the DI container.
|
||||
/// </remarks>
|
||||
/// <returns>The same <see cref="OptionsBuilder{TOptions}"/> instance, to allow for chaining.</returns>
|
||||
public static OptionsBuilder<TOptions> ValidateFluently<TOptions>(this OptionsBuilder<TOptions> optionsBuilder) where TOptions : class
|
||||
{
|
||||
// register a singleton instance of IValidateOptions<TOptions> using the validator
|
||||
optionsBuilder.Services.AddSingleton<IValidateOptions<TOptions>>(
|
||||
serviceProvider => new ValidationOptions<TOptions>(optionsBuilder.Name, serviceProvider.GetRequiredService<IValidator<TOptions>>()));
|
||||
return optionsBuilder;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user