/// <summary> /// Initializes a new instance of the <see cref="ValidateDataAnnotationsBehavior" /> class. /// </summary> /// <param name="validationResultsLogger">Optional validation results logger. It has to implement the interface <see cref="IValidationResultsLogger"/></param> public ValidateDataAnnotationsBehavior(Type validationResultsLogger = null) { if (validationResultsLogger != null) { if (!typeof(IValidationResultsLogger).IsAssignableFrom(validationResultsLogger)) { throw new ArgumentException($"The type of {validationResultsLogger} doesn't implement the interface '{typeof(IValidationResultsLogger)}'!"); } _validationResultsLogger = (IValidationResultsLogger)Activator.CreateInstance(validationResultsLogger); } _validators = new List <IObjectValidator> { new NullCheckObjectValidator(), new DataAnnotationsObjectValidator(), new ValidatableObjectValidator() }; }
/// <summary> /// Initializes a new instance of the <see cref="ValidatingParameterInspector"/> class. /// </summary> /// <param name="validators">The validators.</param> /// <param name="errorMessageGenerator">The error message generator.</param> /// <param name="validationResultsLogger">[Optional] The validation results logger</param> /// <param name="parameterDetailsInfo">The parameter info object for the optional validator skipping.</param> public ValidatingParameterInspector(IEnumerable <IObjectValidator> validators, IErrorMessageGenerator errorMessageGenerator, IValidationResultsLogger validationResultsLogger = null, ParameterDetailsInfo parameterDetailsInfo = null) { _validationResultsLogger = validationResultsLogger; if (validators == null) { throw new ArgumentNullException(nameof(validators)); } if (!validators.Any()) { throw new ArgumentException("At least one validator is required."); } if (errorMessageGenerator == null) { throw new ArgumentNullException(nameof(errorMessageGenerator)); } _validators = validators; _errorMessageGenerator = errorMessageGenerator; _parameterDetailsInfo = parameterDetailsInfo; }