title: StructureMap Inject GetInstance Method
body: <p>I'm using <em>structuremap</em> in a project and for a specific need I want to have access to the <strong>Container.GetInstance(Type type)</strong> method from structuremap.
  Thinking about onion architecture, I don't wan't to have the nuget <em>structuremap</em> referenced in every projects of my solution.</p>
  
  <p>So I have a class in a <strong>Core</strong> project that's supposed to do something like that:</p>
  
  <pre><code>public class CommandDispatcherBase
  {
      public async Task&lt;TCommandResult&gt; DispatchAsync&lt;TCommand, TCommandResult&gt;(TCommand command) 
      {
          // This line
          CommandHandler&lt;TCommand&gt; handler = GetInstance(typeof(CommandHandler&lt;TCommand&gt;)));
          handler.DoSomething();
      }
  }
  </code></pre>
  
  <p>With :</p>
  
  <pre><code>public abstract class CommandHandler&lt;TCommand&gt;
  {
      // Some methods
  }
  </code></pre>
  
  <p>And :</p>
  
  <pre><code>public class RegisterUserHandler : CommandHandler&lt;RegisterUserCommand&gt;
  {
      // Some methods
  }
  </code></pre>
  
  <p>And in my bootstrap registry :</p>
  
  <pre><code>For&lt;CommandHandler&lt;RegisterUserCommand&gt;&gt;().Use&lt;RegisterUserHandler&gt;();
  </code></pre>
  
  <p>But I have no idea how to do. Ideally I would like to have a <strong>delegate</strong> method in my <strong>Core</strong> project like that :</p>
  
  <pre><code>public delegate object CommandHandlerFactory(Type handlerType);
  </code></pre>
  
  <p>In which I would inject the <strong>Container.GetInstance(Type type)</strong> structuremap method but I don't know how to do that.</p>
  
  <p>Any idea ?
  Thanks a lot !</p>