title: Connecting different implementations with StructureMap
body: <p>I have a pretty straightforward generic repository:</p>
  
  <pre><code>public interface IRepository&lt;TEntity, TNotFound&gt;
      where TEntity : EntityObject
      where TNotFound : TEntity, new()
  {
      IList&lt;TEntity&gt; GetAll();
      TEntity With(int id);
      TEntity Persist(TEntity itemToPersist);
      void Delete(TEntity itemToDelete);
  }
  </code></pre>
  
  <p>I want to define a contract for a repository for the type <code>Term</code> without any special behaviour. So it looks like this:</p>
  
  <pre><code>public class TermNotFound : Term
  { public TermNotFound() : base(String.Empty, String.Empty) { } }
  
  
  public interface ITermRepository : IRepository&lt;Term, TermNotFound&gt; { }
  </code></pre>
  
  <p>Now for testing, I want to create an in-memory implementation of the generic repo, so I have this (not finished for brevity):</p>
  
  <pre><code>public class InMemoryRepository&lt;TEntity, TNotFound&gt; : IRepository&lt;TEntity, TNotFound&gt;
      where TEntity : EntityObject
      where TNotFound : TEntity, new()
  {
      private IList&lt;TEntity&gt; _repo = new List&lt;TEntity&gt;();
  
  
      public IList&lt;TEntity&gt; GetAll()
      {
          return this._repo;
      }
  
      public TEntity With(int id)
      {
          return this._repo.SingleOrDefault(i =&gt; i.Id == id) ?? new TNotFound();
      }
  
      public TEntity Persist(TEntity itemToPersist)
      {
          throw new NotImplementedException();
      }
  
      public void Delete(TEntity itemToDelete)
      {
          throw new NotImplementedException();
      }
  }
  </code></pre>
  
  <p>It's not hard to see how I want it to work. For my tests, I want the generic <code>InMemoryRepository</code> implementation to be injected to create my <code>ITermRepository</code>. How hard is that right?</p>
  
  <p>Well, I can't get StructureMap to do it. I have tried using <code>WithDefaultConventions</code> and <code>ConnectImplementationsToTypesClosing(typeof(IRepository&lt;,&gt;))</code> in the scanner without success.</p>
  
  <p>Can someone please help me out?</p>