title: How to use the same generic method for validation of different types
body: <p>I am having an interface IValidator which has a generic method Validate and is intended to validate different objects across the application. For now I am validating User's profile and Login credentials. The problem is, when I try to validate profile or Login class, it always calls the method for the profile even when I try to validate Login details. Here's the code:</p>
  
  <p>IValidator</p>
  
  <pre><code> public interface IValidator
  {
      List&lt;Error&gt; Validate&lt;T&gt;(T request);
  }
  </code></pre>
  
  <p>UserProfileValidator</p>
  
  <pre><code> public class UserProfileValidator : IValidator 
  {
      public List&lt;Error&gt; Validate&lt;T&gt;(T request)
      {
         //Code for profile validation
      }
  }
  </code></pre>
  
  <p>UserLoginValidator</p>
  
  <pre><code> public class UserLoginValidator: IValidator 
  {
      public List&lt;Error&gt; Validate&lt;T&gt;(T request)
      {
         //Code for login validation
      }
  }
  </code></pre>
  
  <p>UserService</p>
  
  <pre><code>   private readonly IValidator _validator; 
  
     public UserService(IValidator validator)
      {
          _validator = validator;
      }
  
  
   public async Task&lt;Response&gt; Login(UserDetail userDetail)
   {
       //this is supposed to validate login details, but validates profile instead
          var errors = _validator.Validate(userDetail); 
   }
  
  public async Task&lt;Response&gt; UpdateProfile(Profile profile)
   {
          var errors = _validator.Validate(profile);
   }
  </code></pre>
  
  <p>Please guide. Thanks</p>