I want to customize a attribute. Say
public class IdExistAttribute : ValidationAttribute
{
protected override ValidationResult IsValid(object value,
ValidationContext validationContext)
{
string id= value.ToString();
if(ListOfId.Contains(id))
{
return new ValidationResult("Id is already existing");
}
return ValidationResult.Success;
}
}
The question is that ListOfId
is from service, I can't consume the service inside the attribute. So how to pass it from outside?
I want to use the attribute as
private string _id;
[IdExist]
public string Id
{
get{return _id;}
set{_id=value;}
}