title: Castle.Windsor lifestyle depending on context?
body: <p>I have a web application where many components are registered using <code>.LifestylePerWebRequest()</code>, now I've decided to implement <strong>Quartz.NET</strong>, a .NET job scheduling library, which executes in separate threads, and not the Request thread.</p>
  
  <p>As such, <code>HttpContext.Current</code> yields <code>null</code>. My services, repositories, and <code>IDbConnection</code> were instanced so far using <code>.LifestylePerWebRequest()</code> because it made it easier to dispose of them when the requests ended.</p>
  
  <p>Now I want to use these components in both scenarios, during web requests I want them to remain unaffected, and in non-request contexts I want them to use a different Lifestyle, I figure I can handle the disposing myself, but how should I go about it for choosing a lifestyle for the components based on the current context?</p>
  
  <p>Currently I register services (for example), like this:</p>
  
  <pre><code>container.Register(
      AllTypes
          .FromAssemblyContaining&lt;EmailService&gt;()
          .Where(t =&gt; t.Name.EndsWith("Service"))
          .WithService.Select(IoC.SelectByInterfaceConvention)
          .LifestylePerWebRequest()
  );
  </code></pre>
  
  <p>I figure I should be using some kind of extension method but I just don't see it..</p>