9using System.Collections.Generic;
10using System.ComponentModel.DataAnnotations;
13using System.Threading.Tasks;
21 internal class DIBasedTestAttribute : ValidationAttribute
23 public DIBasedTestAttribute() : base(
"Unknown validation error") { }
25 public override bool RequiresValidationContext =>
true;
34 protected override ValidationResult IsValid(
object value, ValidationContext validationContext)
36 ApplicationContext applicationContext;
38 if (value is
null)
return ValidationResult.Success;
39 if (validationContext is
null)
throw new ArgumentNullException(nameof(validationContext));
41 applicationContext = (ApplicationContext)validationContext.GetService(typeof(ApplicationContext));
43 if (applicationContext is
null)
45 return new ValidationResult(
"Service provider failed to create the appropriate class!");
48 return ValidationResult.Success;