title: Setting different Castle Windsor lifestyle from different applications using the same installer
body: <p>I have a problem with figuring out what the best way is to register different lifestyles for different applications using the same installers.</p>
  
  <p>I have a web project that use Castle Windsor IoC. Some things are scoped to use PerWebRequest lifestyle. The classes are registered with installers in the respective projects.</p>
  
  <p>All good so far, but I'm thinking about moving some stuff to a windowsService to do some scheduled stuff. This service will resolve the same domain as the web project but get trouble when the classes are registered with PerWebRequest lifestyle. I'd like to change this to Scoped for the service but keep it as it is in the web app. The configuration is done in the installer kept in the respective assemblies. </p>
  
  <p>The installers doesn't know which app is trying to register, but the registrations needs to be with different lifestyle depending on if the installer is registered from the web app or the windows service. </p>
  
  <p>Right now I have restorted to an ugly Hack until I get a better solution.</p>
  
  <pre><code>private static bool scopeLifetime = false;
  public static void SetScopedLifetime()
  {
      scopeLifetime = true;
  }
  
  public void Install(IWindsorContainer container, IConfigurationStore store)
  {
      var registrations = Classes.FromThisAssembly()
          .WithService.DefaultInterfaces();
  
      if (scopeLifetime)
      {
          container.Register(registrations.LifestyleScoped());
      }
      else
      {
          container.Register(registrations.LifestylePerWebRequest());
      }
  }
  </code></pre>
  
  <p>What is the correct way to tell windsor what I would like to do, without the installer needing to know the context?</p>