/// <summary>
 /// Initializes a new instance of the <see cref="FluentValidationRules"/> class.
 /// </summary>
 /// <param name="validatorFactory">Validator factory.</param>
 /// <param name="rules">External FluentValidation rules. Rule with the same name replaces default rule.</param>
 /// <param name="loggerFactory"><see cref="ILoggerFactory"/> for logging. Can be null.</param>
 public FluentValidationRules(
     IValidatorFactory?validatorFactory       = null,
     IEnumerable <FluentValidationRule>?rules = null,
     ILoggerFactory?loggerFactory             = null)
 {
     _validatorFactory = validatorFactory;
     _logger           = loggerFactory?.CreateLogger(typeof(FluentValidationRules)) ?? NullLogger.Instance;
     _rules            = FluentValidationRuleProvider.CreateDefaultRules().OverrideRules(rules);
 }
Example #2
0
 /// <summary>
 /// Initializes a new instance of the <see cref="FluentValidationOperationFilter"/> class.
 /// </summary>
 /// <param name="swaggerGenOptions">Swagger generation options.</param>
 /// <param name="validatorFactory">FluentValidation factory.</param>
 /// <param name="rules">Custom rules. Is not set <see cref="FluentValidationRuleProvider.CreateDefaultRules"/> will be used.</param>
 /// <param name="loggerFactory">Logger factory.</param>
 public FluentValidationOperationFilter(
     IOptions <SwaggerGenOptions> swaggerGenOptions,
     IValidatorFactory?validatorFactory       = null,
     IEnumerable <FluentValidationRule>?rules = null,
     ILoggerFactory?loggerFactory             = null)
 {
     _swaggerGenOptions = swaggerGenOptions.Value;
     _validatorFactory  = validatorFactory;
     _logger            = loggerFactory?.CreateLogger(typeof(FluentValidationRules)) ?? NullLogger.Instance;
     _rules             = FluentValidationRuleProvider.CreateDefaultRules().OverrideRules(rules);
 }