title: Using SimpleInjector Is there a way to replicate RegisterWebApiRequest<T>() with .net 4/webapi 1?
body: <p>Following up on this <a href="https://stackoverflow.com/questions/22311361/">question</a>.  I'm working through example of using SimpleInjector and WebAPI.   Unfortunately, where I want to utilize WebAPI  <a href="https://support.microsoft.com/kb/2568167" rel="nofollow">KB2568167</a>  and <a href="https://support.microsoft.com/kb/2915689" rel="nofollow">KB2915689</a> prevent me from upgrading to .net 4.5.    So I'm stuck using .net 4.0 &amp; WebAPI v1 (4.0.30506.0) at the moment. </p>
  
  <p>Is there a way to replicate the <code>RegisterWebApiRequest&lt;T&gt;()</code> scoping with the older version of WebAPI?</p>
  
  <p>While I the nu-get packages only contain .net 4.5 versions, I was able to download the code and get a framework 4.0 compile without much trouble.   When calling <code>var container = request.GetDependencyScope()</code> in my Message Handler a <code>SimpleInjectorWebApiDependencyResolver</code> class is returned.   Attempting to retrieve an instance out of the container like so:</p>
  
  <pre><code>  var poco = (SimplePOCO) container.GetService(typeof(SimplePOCO));
  </code></pre>
  
  <p>results in the following error:: </p>
  
  <blockquote>
    <p>The registered delegate for type SimplePOCO threw an exception. The
    SimplePOCO is registered as 'Web API Request' lifestyle, but the
    instance is requested outside the context of a Web API Request.</p>
  </blockquote>
  
  <p>Am I just missing something in my config?  Is there an alternative -- like creating my own message handler?</p>
  
  <hr>
  
  <h2>UPDATE</h2>
  
  <p>After posting the <a href="https://simpleinjector.codeplex.com/workitem/20812" rel="nofollow">codeplex issue</a>, I went back to basics.  I took a plain vanilla Mvc WebApi project, referenced my compiles of <code>SimpleInjector</code>, <code>SimpleInjector.Integration.WebApi</code>, and  <code>SimpleInjector.Extensions.ExecutionContextScoping</code>.   </p>
  
  <p>Like @blueling  I was able to get it working in a message handler. </p>
  
  <p>So what's different?   One thought I had is that my non-functioning project is bare bones -- just WebApi and slim web.config.   None of the scaffolding and fluff that come with the base project templates are in my solution.  Tomorrow I plan to compare the work example to the non-working one reference-by-reference and web.config setting at a time. </p>
  
  <hr>
  
  <h2>UPDATE 2</h2>
  
  <p>So a little more debugging, and sure enough Dispose() is being called on the DependencyResolver implementation, but not by me....</p>
  
  <blockquote>
    <p><img src="https://i.stack.imgur.com/Knkop.png" alt="Call stack for dispose"></p>
  </blockquote>