title: Cannot implicitly cast to IEnumerable<T>... but I can the other way... why?
body: <p>I'm learning about the Repository Pattern so I can apply it to WPF MVVM. I got this piece of code from another post on SO...</p>
  
  <pre><code>public interface IRepository : IDisposable
  {
      IEnumerable&lt;T&gt; GetAll&lt;T&gt;();
  }
  </code></pre>
  
  <p>So I tried to make it work for me in the following manner...</p>
  
  <pre><code>class CustomersRepository : IRepository
  {
      public IEnumerable&lt;Models.Customer&gt; GetAll&lt;T&gt;()
      {
          DataView results;
  
          // some DAL retrieval code
  
          foreach (DataRowView row in results)
          {
              yield return new Models.Customer(row["Label"].ToString());
          }
      }
  }
  </code></pre>
  
  <p>And by calling the method from my Model...</p>
  
  <pre><code>public static IEnumerable&lt;Customer&gt; ReadCustomers()
  {
      IRepository repository = new CustomersRepository();
      return repository.GetAll&lt;Models.Customer&gt;();
  }
  </code></pre>
  
  <p>But I get an error, <strong>"CustomersRepository does not implement interface member "IRepository.GetAll&lt; T >()". "CustomersRepository.GetAll&lt; T >()" cannot implement "IRepository.GetAll&lt; T >()" because it does not have the matching return type of "System.Collections.Generic.IEnumerable&lt; T >"</strong>.</p>
  
  <hr>
  
  <p>However, if I define the type argument in the interface's identifier instead, and I remove the type argument from the method call...</p>
  
  <pre><code>public interface IRepository&lt;T&gt; : IDisposable
  {
      IEnumerable&lt;T&gt; GetAll();
  }
  </code></pre>
  
  <p>...and I adjust the implementation, and the call from my Model accordingly...</p>
  
  <pre><code>class CustomersRepository : IRepository&lt;Models.Customer&gt;
  {
      public IEnumerable&lt;Models.Customer&gt; GetAll()
      {
          // same body content
      }
  }
  </code></pre>
  
  <p>...</p>
  
  <pre><code>public static IEnumerable&lt;Customer&gt; ReadCustomers()
  {
      IRepository&lt;Models.Customer&gt; repository = new CustomersRepository();
      return repository.GetAll();
  }
  </code></pre>
  
  <p>...then it works perfectly!</p>
  
  <p>My questions are:</p>
  
  <ol>
  <li>Why can't it implicitly cast the yield return in my original attempt? Is this by design, or am I misinterpreting how type arguments work?</li>
  <li>Considering that I want to loose-couple the CustomersRepository to my Customer model, and considering that the Model represents a single data entity, is there a better way than using a static factory method in my Customer model class?</li>
  </ol>