// Copyright (c) The Geekeey Authors
// SPDX-License-Identifier: EUPL-1.2
using Microsoft.Extensions.DependencyInjection;
namespace Geekeey.Request.Validation;
///
/// Provides extension methods for configuring and registering validator services in the .
///
public static class ServiceCollectionExtensions
{
///
/// Adds validator services to the specified .
///
/// The service collection to which the validator services will be added.
/// An instance of to configure the validator registrations.
public static IValidatorBuilder AddValidation(this IServiceCollection services)
{
ArgumentNullException.ThrowIfNull(services);
services.AddOptions();
services.AddTransient();
return new ValidatorBuilder(services);
}
///
/// Adds validator services to the specified
/// and configures them using the provided .
///
/// The service collection to which the validator services will be added.
/// A delegate to configure the validator builder.
/// The service collection with the validator services added.
public static IServiceCollection AddValidation(this IServiceCollection services, Action configure)
{
ArgumentNullException.ThrowIfNull(services);
ArgumentNullException.ThrowIfNull(configure);
configure(services.AddValidation());
return services;
}
private sealed class ValidatorBuilder(IServiceCollection services) : IValidatorBuilder
{
public IServiceCollection Services { get; } = services;
}
}