ASP.NET Core - Create custom model validation
<p>In previous versions of ASP.NET MVC the way to add custom validation to your model was by implementing the <code>IValidatableObject</code> and implementing your own <code>Validate()</code> method.</p>
<p>Here's what I have implemented:</p>
<pre class="lang-cs prettyprint-override"><code>public class BestModelEver: IValidatableObject 
{
    public DateTime? Birthday { get; set; }

    public IEnumerable&lt;ValidationResult&gt; Validate(ValidationContext validationContext) 
    {
        if (Birthday.HasValue) 
        {
          yield return new ValidationResult(&quot;Error message goes here&quot;);
        }
    }
}
</code></pre>
<p>Is this still the recommended way of adding custom validation to a model in ASP.NET Core?  Using <code>IValidatableObject</code> takes on a <code>System.ComponentModel.DataAnnotations</code> dependency.</p>