title: Simple injector register per web request and with context
body: <p>There is <code>RegisterPerWebRequest</code> and <code>RegisterWithContext</code> (this one is not originally shipped with simple injector, however it supplied on their <a href="https://simpleinjector.codeplex.com/wikipage?title=ContextDependentExtensions&amp;referringTitle=Advanced-scenarios">advanced-scenarios section</a>). Separately both approaches works fine but I need to combine them.</p>
  
  <p>I figured out that in <code>RegisterPerWebRequest</code> used <code>new WebRequestLifestyle()</code> lifestyle (found it <a href="https://simpleinjector.codeplex.com/SourceControl/latest#SimpleInjectorV2.3/SimpleInjector.Integration.Web/SimpleInjectorWebExtensions.cs">there</a>). So instead of using <code>Lifestyle.Transient</code> <code>RegisterWithContext</code> I supplied <code>new WebRequestLifestyle()</code> but it appears that <code>DependencyContext.ImplementationType</code> and <code>DependencyContext.ServiceType</code> are null.</p>
  
  <p>What is wrong with that?</p>
  
  <p><strong>Update 1.</strong></p>
  
  <p>So I wanted to Register type per web request as does <code>RegisterPerWebRequest</code> but also to be able to provide instance creator with access to type where registered type is injected.</p>
  
  <p>I modified (extracted lifestyle as a parameter) <code>RegisterWithContext</code> to be:</p>
  
  <pre><code>public static void RegisterWithContext&lt;TService&gt;(
      this Container container,
      Func&lt;DependencyContext, TService&gt; contextBasedFactory, Lifestyle lifestyle)
      where TService : class
  {
      //original code
  
      container.Register&lt;TService&gt;(rootFactory, lifestyle);
  
      //original code
  }
  </code></pre>
  
  <p>And for "per web request and with context" registration I expected to be able use:</p>
  
  <pre><code>container.RegisterWithContext&lt;IUnitOfWork&gt;(dependencyContext =&gt;
  {
        var implementationType = dependencyContext.ImplementationType;
        //do some stuff and return preconfigured UnitOfWork
  }, new WebRequestLifestyle());
  </code></pre>
  
  <p>And as I already mentioned <code>dependencyContext.ImplementationType</code> is <code>NULL</code></p>
  
  <p>I am using SimpleInjector 2.3.0.0</p>