title: Simple Injector: Replace registered type at runtime
body: <p>Is there any way in Simple Injector to replace the default of one type at runtime as <code>containter.Inject()</code> in Structure Map? I borrow the <a href="http://structuremap.github.io/registration/changing-configuration-at-runtime/" rel="nofollow noreferrer">code</a> using Structure Map as follows</p>
  
  <pre><code>var container = new Container(x =&gt; { x.For&lt;IFoo&gt;().Use&lt;AFoo&gt;(); });
  container.GetInstance&lt;IFoo&gt;().ShouldBeOfType&lt;AFoo&gt;();
  container.Configure(x =&gt; x.For&lt;IFoo&gt;().Use&lt;BFoo&gt;());
  
  // The default of IFoo is now different
  container.GetInstance&lt;IFoo&gt;().ShouldBeOfType&lt;BFoo&gt;();
  
  // or use the Inject method that's just syntactical
  // sugar for replacing the default of one type at a time
  container.Inject&lt;IFoo&gt;(new CFoo());
  
  container.GetInstance&lt;IFoo&gt;().ShouldBeOfType&lt;CFoo&gt;();
  </code></pre>
  
  <p>My context</p>
  
  <p>Register container</p>
  
  <pre><code>// bypass verify was removed for short
  _container.Register&lt;HttpContextBase&gt;(() =&gt; new HttpContextWrapper(HttpContext.Current)); 
  _container.Register(() =&gt; _container.GetInstance&lt;HttpContextBase&gt;().User.Identity);
  </code></pre>
  
  <p>My service</p>
  
  <pre><code>public class MyService : IMyService
  {
      public MyService(IIdentity identity)
      {
          //...
      }
      //...
  }
  </code></pre>
  
  <p>There is no problem with my app. It worked. But in my unit tests (real local DB without mock), I want to replace IIdentity with logged in user. I used Structure Map and it worked. Now I do not how to make it works with Simple Injector.</p>