title: Get all implementations of a generic service type - including open generics
body: <h3>Background</h3>
  
  <p>I am writing some integration tests where I test implementations of a particular interface, <code>IQueryMapping&lt;TSource, TDest&gt;</code>. This interface exists to map from an <code>IQueryable&lt;TSource&gt;</code> to an <code>IQueryable&lt;TDest&gt;</code>. I want to make sure that they do 
  not throw exceptions when compiling a query using Entity Framework.</p>
  
  <h3>The Task</h3>
  
  <p>I am lazy and I don't want to have to update my tests every time I create a new mapping! All I want to do is ensure that every mapping which is used by my application will pass the test. I can bootstrap my container and then find all implementations that are registered with it like so:</p>
  
  <pre><code>from r in Container.GetCurrentRegistrations()
  let t = r.ServiceType
  where t.IsGenericType &amp;&amp; t.GetGenericTypeDefinition() == typeof (IQueryMapping&lt;,&gt;)
  select r.GetInstance()
  </code></pre>
  
  <p>So far, so good!</p>
  
  <h3>The Problem</h3>
  
  <p>Alongside my concrete implementations, I have a default open generic mapper which performs basic automatic property mapping (remember, I am lazy and don't want to do this manually!)</p>
  
  <pre><code>container.RegisterOpenGeneric(typeof(IQueryMapping&lt;,&gt;), typeof(DefaultAutoMapping&lt;,&gt;));
  </code></pre>
  
  <p>Unfortunately, open generics don't seem to appear in <code>Container.GetCurrentRegistrations()</code> call. From the <a href="https://simpleinjector.org/ReferenceLibrary/html/M_SimpleInjector_Container_GetCurrentRegistrations.htm" rel="nofollow">docs</a>:</p>
  
  <blockquote>
    <p>Returns an array with the current registrations. This list contains all explicitly registered types, and all implicitly registered instances. Implicit registrations are all concrete unregistered types that have been requested, all types that have been resolved using unregistered type resolution (using the ResolveUnregisteredType event), and requested unregistered collections. Note that the result of this method may change over time, because of these implicit registrations.</p>
  </blockquote>
  
  <p>What I'd really like is for Simple Injector to <strong>tell me about every requested occurrence of <code>IQueryMapping&lt;,&gt;</code> in all registered components</strong>.</p>
  
  <p>For example, if I have left <code>IQueryMapping&lt;Foo, Bar&gt;</code> as an open generic <code>DefaultAutoMapping&lt;,&gt;</code> and a registered component has the constructor signature</p>
  
  <pre><code>public MyComponent(IQueryMapping&lt;Foo, Bar&gt; mapping)
  {
     ...
  }
  </code></pre>
  
  <p>I would like the container to <strong>tell me about this specialised <code>IQueryMapping&lt;,&gt;</code></strong>, so that I can request an instance of it and run it through my test.</p>