Created
November 23, 2009 19:23
-
-
Save jfromaniello/241305 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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