title: Simple Injector: Register Conditional vs RegisterSingleton
body: <p>Context: I am trying to capture multiple events in our api using serilog and the elastic search sink, these events include: GET actions(regular web api flow) as well as login attempts (Owin).
  I am registering serilog like this:</p>
  <pre><code>container.RegisterConditional(
      typeof(ICustomLogger),
      c =&gt; typeof(CustomLogger&lt;&gt;).MakeGenericType(
          c.Consumer?.ImplementationType ?? typeof(object)),
      Lifestyle.Singleton,
      c =&gt; true);
  </code></pre>
  <p>I am doing this for Owin registration:</p>
  <pre><code>app.Use(async (context, next) =&gt;
  {
      using (var scope = container.BeginExecutionContextScope())
      {
          await next.Invoke();
      }
  });
  </code></pre>
  <p>Then when I call  <code>container.Verify();</code> the logger constructor gets called(as expected).
  However when I call the logger from my <code>OAuthAuthorizationServerProvider</code> implementation like this:
  <code>var logger = ObjectFactory.GetInstance&lt;ICustomLogger&gt;();</code> the constructor gets called again, meaning the singleton is not really a singleton anymore, I am totally aware of the service locator antipattern(don't really have much time to refactor that piece right now), what is interesting is that if I change the logger registration to the following (getting rid of the type piece) then only one instance is created:</p>
  <pre><code>container.RegisterSingleton(typeof(ICustomLogger), typeof(CustomLogger))
  </code></pre>
  <p>The reason why I am trying to use the first option is because I want to be able to use <code>.ForContext(typeof(T));</code> for serilog, and in case you are wondering how I am registering the <code>ObjectFactory</code> piece here it is:
  Class:</p>
  <pre><code>public static class ObjectFactory
  {
      public static Container container;
  
      public static void SetContainer(Container container)
      {
          ObjectFactory.container = container;
      }
  
      public static T GetInstance&lt;T&gt;() where T : class
      {
          return container.GetInstance&lt;T&gt;();
      }
  }
  </code></pre>
  <p>Registration(from my main bootstrapper):</p>
  <pre><code>ObjectFactory.SetContainer(container);
  </code></pre>
  <p>So my main question is: Why is only one instance created with <code>RegisterSingleton</code> but multiple are created with <code>RegisterConditional</code> and <code>Lifestyle.Singleton</code>?</p>