using FluentValidation; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection.Extensions; using PoweredSoft.CQRS.Abstractions; using PoweredSoft.CQRS.Abstractions.Discovery; using PoweredSoft.CQRS.Discovery; using System; using System.Collections.Generic; using System.Text; namespace PoweredSoft.CQRS.FluentValidation { public static class ServiceCollectionExtensions { private static IServiceCollection AddFluentValidator(this IServiceCollection services) where TValidator : class, IValidator { services.AddTransient, TValidator>(); return services; } public static IServiceCollection AddCommandWithValidator(this IServiceCollection services) where TCommand : class where TCommandHandler : class, ICommandHandler where TValidator : class, IValidator { return services.AddCommand() .AddFluentValidator(); } public static IServiceCollection AddCommandWithValidator(this IServiceCollection services) where TCommand : class where TCommandHandler : class, ICommandHandler where TValidator : class, IValidator { return services.AddCommand() .AddFluentValidator(); } public static IServiceCollection AddQueryWithValidator(this IServiceCollection services) where TQuery : class where TQueryHandler : class, IQueryHandler where TValidator : class, IValidator { services.AddQuery() .AddFluentValidator(); return services; } } }