I have a .NET 4.0, WPF app which uses Caliburn 1.5.2 e Autofac 3.0.2.
I want to use command line arguments to customize the building of the IoC container.
The problem is that the command line arguments are only available at Appplication.OnStartup
(link) and that will only happen when the Bootstrapper.Configure
has already been called.
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 (Autofac's AutoActivation extension), so the best moment to choose which type to use is when registering it in the container.
I'm considering:
Delaying the initialization of the services to the app's main viewmodel.
Split container configuration logic in two stages, one in
Bootstrapper.Configure
and another inBootstrapper.OnStartup
.
The main caveats with that are:
- The viewmodel would depend on the services just to initialize them.
- With container configuration split in two parts, I'd have to look for problems in dependency resolution.
- I think it would be nicer to have container configuration in only one place.
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.
I wonder if anyone knows a nicer way of doing that.