Skip to content

Instantly share code, notes, and snippets.

@jfromaniello
Created November 23, 2009 19:23
Show Gist options
  • Save jfromaniello/241305 to your computer and use it in GitHub Desktop.
Save jfromaniello/241305 to your computer and use it in GitHub Desktop.
public class ValidationBase
{
private static readonly IWindsorContainer CONTAINER;
public static readonly IEntityValidator EntityValidator;
static ValidationBase()
{
CONTAINER = new WindsorContainer();
var validationConfigurations = new NHVConfigurator();
validationConfigurations.Configure(CONTAINER);
EntityValidator = CONTAINER.Resolve<IEntityValidator>();
}
}
public static class EntityValidatorExtensions
{
public static IList<IInvalidValueInfo> GetErrorsFor<TEntity, TProperty>(
this TEntity entity, Expression<Func<TEntity, TProperty>> property) where TEntity : class
{
return ValidationBase.EntityValidator.Validate(entity, property);
}
public static IList<string> GetMessagesFor<TEntity,TProperty>(
this TEntity entity, Expression<Func<TEntity, TProperty>> property) where TEntity : class
{
return entity.GetErrorsFor(property).Select(m => m.Message).ToList();
}
public static IList<IInvalidValueInfo> GetErrors<TEntity>(
this TEntity entity) where TEntity : class
{
return ValidationBase.EntityValidator.Validate(entity);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment