Advertisement
Guest User

Untitled

a guest
Jul 26th, 2017
49
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.95 KB | None | 0 0
  1. public class DataValidationInterceptor : IServiceInterceptor
  2. {
  3. private readonly ICurrentContext currentContext;
  4.  
  5. public DataValidationInterceptor(ICurrentContext currentContext) {
  6. this.currentContext = currentContext;
  7. }
  8.  
  9. public int AfterOrder => 1;
  10.  
  11. public int BeforeOrder => 1;
  12.  
  13. public void BeforeProceed(InvocationContext context) {
  14. foreach (var item in context.Arguments) {
  15. if (item == null)
  16. continue;
  17.  
  18. var itemType = item.GetType();
  19. if (itemType.IsPrimitive || itemType.IsArray)
  20. continue;
  21.  
  22. var type = typeof(ICustomValidator<>).MakeGenericType(item.GetType());
  23. var validator = (ICustomValidator)Container.Resolve(type);
  24. if (validator == null)
  25. continue;
  26.  
  27. validator.Validate(item, currentContext.Current.ActionType);
  28. }
  29. }
  30.  
  31. public void AfterProceed(InvocationContext context) {
  32. }
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement