Ejemplo n.º 1
0
 /// <summary>
 /// Validates <paramref name="model"/> synchronously using runtime type of model.
 /// Best for framework code where TModel can't be determined.
 /// </summary>
 /// <typeparam name="TModel">Type of model to validate.</typeparam>
 /// <param name="dispatcher">A validation dispatcher.</param>
 /// <param name="model">An instance to validate.</param>
 /// <returns><see cref="IValidationResult"/> describing success or validation failure.</returns>
 public static IValidationResult Validate(this IValidationDispatcher dispatcher, object model)
 {
     try
     {
         Task <IValidationResult> task = dispatcher.ValidateAsync(model);
         task.Wait();
         return(task.Result);
     }
     catch (AggregateException e)
     {
         throw e.InnerException;
     }
 }
        protected virtual async Task ValidateAsync(T command)
        {
            IValidationResult result = null;

            if (validationHandler != null)
            {
                result = await validationHandler.HandleAsync(command);
            }
            else if (validationDispatcher != null)
            {
                result = await validationDispatcher.ValidateAsync(command);
            }

            if (result != null)
            {
                result.ThrowIfNotValid();
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// A method responsible for validating commands.
        /// </summary>
        /// <typeparam name="TCommand">A type of the command.</typeparam>
        /// <param name="command">An instance of command to validate.</param>
        /// <returns>A continuation task.</returns>
        protected virtual async Task ValidateAsync <TCommand>(TCommand command)
        {
            IValidationResult result = await validationDispatcher.ValidateAsync(command);

            result.ThrowIfNotValid();
        }