title: How do I create Tagged Litetimes in Simple Injector?
body: <p>What I want is Simple Injector's equivalent of Autofac's <a href="https://autofaccn.readthedocs.io/en/latest/lifetime/working-with-scopes.html#tagging-a-lifetime-scope" rel="nofollow noreferrer">tagged lifetimes</a>: </p>
  
  <p>I've read Simple Injector's documentation. The most probable way to accomplishing this is by using Simple Injector's <a href="https://simpleinjector.readthedocs.io/en/latest/lifetimes.html#customlifestyles" rel="nofollow noreferrer">custom lifestyles</a>:</p>
  
  <p>But the documentation on it is very sparse and I can't figure out how to get what I want from it. How can I get the equivalent of Autofac's tagged scopes in Simple Injector?</p>
  
  <p>Example of something I would want:</p>
  
  <pre class="lang-cs prettyprint-override"><code>// Arrange
  var container = new Container();
  
  container.Register&lt;ICommand, ConcreteCommand&gt;(new AsyncScopedLifestyle());
  container.Register&lt;IDBContext, ConcreteDbContext&gt;(new AsyncScopedLifestyle("dbContext"));
  
  using (AsyncScopedLifestyle.BeginScope(container))
  {
      // Act
      var iCommandInstance1 = container.GetInstance&lt;ICommand&gt;();
      IDBContext iDbContextInstance1 = null;
      IDBContext iDbContextInstance2 = null;
  
      using (AsyncScopedLifestyle.BeginScope(container, "dbContext"))
      {
          var iCommandInstance2 = container.GetInstance&lt;ICommand&gt;();
          iDbContextInstance1 = container.GetInstance&lt;IDBContext&gt;();
  
          // Call things that depend on IDBContext here
  
          // Assert
          Assert.IsTrue(object.ReferenceEquals(iCommandInstance1, iCommandInstance2));
      }
  
      using (AsyncScopedLifestyle.BeginScope(container, "dbContext"))
      {
          var iCommandInstance3 = container.GetInstance&lt;ICommand&gt;();
          iDbContextInstance2 = container.GetInstance&lt;IDBContext&gt;();
  
          // Call things that depend on IDBContext here
  
          // Assert
          Assert.IsTrue(object.ReferenceEquals(iCommandInstance1, iCommandInstance3));
      }
  
      Assert.IsFalse(object.ReferenceEquals(iDbContextInstance1, iDbContextInstance2));
  }
  </code></pre>
  
  <p>In my case it would not make sense to have the two <code>IDBContext</code> instances be the same.</p>