Files
Nemera/src/Lumina.Presentation.Web/Common/Utilities/OptionsBuilderValidationUtilities.cs
T
BinaryAlley 727aa33318 Formats code comments as sentences in the production sources.
Capitalizes the first word and adds the terminal period across the domain, application, data access, infrastructure, API and web layers and the plugins. No comment is reworded. The change also normalizes the TODO bodies to lowercase, leaves commented-out code untouched, corrects the Threat/Treat typo and the dangling hyphen in the exception middleware, and collapses two accidental repeated terminal periods.
2026-11-16 18:16:17 +02:00

31 lines
1.6 KiB
C#

#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;
}
}