title: Unity, RegisterType<> and Singleton objects
body: <p>I am using Unity to instantiate some objects and I'm finding that no matter what I try, Unity is creating singletons for my objects.</p>
  
  <p>According to the documentation:
  <a href="http://msdn.microsoft.com/en-us/library/dd203242.aspx#Y500" rel="nofollow noreferrer">http://msdn.microsoft.com/en-us/library/dd203242.aspx#Y500</a> </p>
  
  <p>With the following code I should be getting a different instance every time the interface gets resolved.</p>
  
  <pre><code>IUnityContainer myContainer = new UnityContainer();  
  
  // Register a default (un-named) type mapping with a transient lifetime  
  myContainer.RegisterType&lt;IMyObject, MyRealObject&gt;();  
  // Following code will return a new instance of MyRealObject  
  myContainer.Resolve&lt;IMyObject&gt;();  
  </code></pre>
  
  <p>But instead I'm getting a singleton instance.</p>
  
  <p>Below is my declaration. <strong>Global.asax</strong></p>
  
  <pre><code>// This should get me a singleton  
  container.RegisterType&lt;IRetailerService, RetailerService&gt;(new ContainerControlledLifetimeManager(), new InjectionConstructor());  
  // This is the one giving me trouble.
  container.RegisterType&lt;IInStoreRetailersViewModelBuilder, InStoreRetailersViewModelBuilder&gt;(new InjectionConstructor(container.Resolve&lt;IRetailerService&gt;()));  
  container.RegisterType&lt;CollectController&gt;(new InjectionConstructor(container.Resolve&lt;IInStoreRetailersViewModelBuilder&gt;()));  
  </code></pre>
  
  <p><strong>Controller</strong></p>
  
  <pre><code>private readonly IInStoreRetailersViewModelBuilder _inStoreRetailersViewModelBuilder;  
  
  public CollectController(IInStoreRetailersViewModelBuilder inStoreRetailersViewModelBuilder)  
  {  
      this._inStoreRetailersViewModelBuilder = inStoreRetailersViewModelBuilder;  
  }  
  
  public ActionResult Index()  
  {  
      InStoreViewModel viewModel = this._inStoreRetailersViewModelBuilder.WithRetailers().WithPostcode().Build();  
  }  
  </code></pre>
  
  <p>If I open Chrome and run the Index action, and then I go and open internet explorer and call the Index action, on the second call, in the constructor the inStoreRetailersViewModelBuilder parameter that gets injected is the one generated on the first call (with Chrome).</p>
  
  <p>I've tried using the PerResolveLifetimeManager() and even the PerHttpRequestLifetime() from this thread: <a href="https://stackoverflow.com/questions/5187562/mvc-ef-datacontext-singleton-instance-per-web-request-in-unity">MVC, EF - DataContext singleton instance Per-Web-Request in Unity</a></p>
  
  <p>But nothing seems to give me a brand new instance. Anyone can shed some light on what I may be doing wrong here?</p>