Beispiel #1
0
        public ValidationResult Validate(object command)
        {
            Type validatorGenericType = typeof(IValidator <>);
            Type validatorType        = validatorGenericType.MakeGenericType(command.GetType());

            IValidator validator = (IValidator)_serviceProvider.GetService(validatorType);

            if (validator == null)
            {
                return(new ValidationResult());
            }

            var validationResult = validator.Validate(command);

            return(new ValidationResult
            {
                Errors = validationResult.Errors.Select(x => new ValidationError
                {
                    ErrorCode = x.ErrorCode,
                    Message = x.ErrorMessage,
                    Property = x.PropertyName
                }).ToArray()
            });
        }