title: Automatically resolve Interface<T> to Implementation<T> in StructureMap (differ only by generic type T)
body: <p>I have an interface (<code>IRepository&lt;T&gt;</code>) that is currently being extended for each specific repository, ie: <code>IUserRepository : IRepository&lt;User&gt;</code>.</p>
  
  <p>Each of these interfaces has corresponding concrete classes, ie: <code>UserRepository : Repository&lt;User&gt;, IUserRepository</code>.</p>
  
  <p>These individual repositories don't add any additional functionality, they are all empty interfaces/classes that are used simply to pass the generics around.</p>
  
  <p>I use StructureMap to resolve <code>IUserRepository</code> into <code>UserRepository</code> using a Registry with an assembly scanner and some naming conventions.</p>
  
  <p>I'd like this to move to a way more optimised state, where instead of passing around instances of <code>IUserRepository</code> and getting it resolved to <code>UserRepository</code>, I can pass around <code>IRepository&lt;User&gt;</code> and have it resolved to <code>Repository&lt;User&gt;</code>.</p>
  
  <p>This would remove the need to create these extra empty interfaces and classes.</p>
  
  <p>I can't work out a way to use StructureMap's configuration to setup this generic mapping.  Something like this:</p>
  
  <pre><code>For(typeof(IRepository&lt;&gt;).Use(typeof(Repository&lt;&gt;)).WithTheGenericTypeFromTheInterfaceSuppliedAsATypeParameter();
  </code></pre>
  
  <p><strong>Edit</strong></p>
  
  <p>After getting the first couple of answers, I want to clarify this a bit more.</p>
  
  <p>I don't want to create individual classes for the <code>For</code> bit of the configuration.  I want to have the following classes/interfaces in my code:</p>
  
  <ul>
  <li><code>IRepository&lt;T&gt; where T : Entity</code></li>
  <li><code>Repository&lt;T&gt; : IRepository&lt;T&gt; where T : Entity</code></li>
  <li><code>Person : Entity</code></li>
  <li><code>Product : Entity</code></li>
  <li><code>Order : Entity</code></li>
  <li><code>Whatever : Entity</code></li>
  </ul>
  
  <p>And have the following mappings achieved with convention:</p>
  
  <pre><code>IRepository&lt;Person&gt; =&gt; Repository&lt;Person&gt;
  IRepository&lt;Product&gt; =&gt; Repository&lt;Product&gt;
  IRepository&lt;Order&gt; =&gt; Repository&lt;Order&gt;
  IRepository&lt;Whatever&gt; =&gt; Repository&lt;Whatever&gt;
  </code></pre>
  
  <p>But I <em>do not</em> want to have to create a mapping for each one, ala:</p>
  
  <pre><code>For&lt;IRepository&lt;Person&gt;&gt;().Use&lt;Repository&lt;Person&gt;&gt;();
  For&lt;IRepository&lt;Product&gt;&gt;().Use&lt;Repository&lt;Product&gt;&gt;();
  For&lt;IRepository&lt;Order&gt;&gt;().Use&lt;Repository&lt;Order&gt;&gt;();
  For&lt;IRepository&lt;Whatever&gt;&gt;().Use&lt;Repository&lt;Whatever&gt;&gt;();
  </code></pre>
  
  <p>I want a single mapping that will work for any IRepository:</p>
  
  <pre><code>For&lt;IRepository&lt;&gt;&gt;().Use&lt;Repository&lt;&gt;&gt;().WithTheSameGenericType();
  </code></pre>
  
  <p>I would then use this to inject the repositories into services:</p>
  
  <pre><code>public MyService(IRepository&lt;User&gt; userRepository)
  </code></pre>
  
  <p>And expect that to be resolved to a <code>Repository&lt;User&gt;</code> at runtime.</p>