title: Customize container configuration with command line arguments
body: <p>I have a .NET 4.0, WPF app which uses Caliburn 1.5.2 e Autofac 3.0.2. </p>
  
  <p>I want to use command line arguments to customize the building of the IoC container. </p>
  
  <p>The problem is that the command line arguments are only available at <code>Appplication.OnStartup</code> (<a href="http://blogs.msdn.com/b/avip/archive/2008/10/27/wpf-supporting-command-line-arguments-and-file-extensions.aspx" rel="nofollow">link</a>) and that will only happen when the <code>Bootstrapper.Configure</code> has already been called.</p>
  
  <p>The reason I want to do that is because I have some services in this application (usb device communication, web services) that I'd like to be able to replace with mocking instances. These services are initialized right after registration (<a href="https://code.google.com/p/autofac/wiki/Startable" rel="nofollow">Autofac's AutoActivation extension</a>), so the best moment to choose which type to use is when registering it in the container.</p>
  
  <p>I'm considering:</p>
  
  <ul>
  <li><p>Delaying the initialization of the services to the app's main viewmodel. </p></li>
  <li><p>Split container configuration logic in two stages, one in <code>Bootstrapper.Configure</code> and another in <code>Bootstrapper.OnStartup</code>.</p></li>
  </ul>
  
  <p>The main caveats with that are:</p>
  
  <ul>
  <li>The viewmodel would depend on the services just to initialize them.</li>
  <li>With container configuration split in two parts, I'd have to look for problems in dependency resolution. </li>
  <li>I think it would be nicer to have container configuration in only one place.</li>
  </ul>
  
  <p>I also thought about looking for Main(string[] args) and caching the parameters in a static instance, but that code is autogenerated in a WPF app, and interfering with that seemed a little too extreme.</p>
  
  <p>I wonder if anyone knows a nicer way of doing that.</p>