In my current solution I have 18 projects and most of them have their own configuration files (app.config or web.config). Each project uses single shared BLL assembly. I’m using Autofac to handle dependencies but haven’t come with a decent way of managing my configuration.
Configuration entries are roughly the same, but values are different. Some projects use custom config secions and some are not.
I ended up with:
- Create single autofac bootstrapper class to register all dependencies except configuration file wrappers.
- Create separate assembly (referenced by all projects) with IConfiguration interface.
- Create each project’s own implementation of IConfiguration.
- Bootstrap dependencies in each project’s appropriate place via shared bootstrapper.
- Register project’s own IConfiguration implenentation separately after bootstrap registration.
I’m very new to Autofac and DI in general and striving to find a good balance between complexity and extensibility.
Are there better ways to manage configuration files?
Thank you.
In Autofac you use Modules for this purpose. Groups of related components are encapsulated in a module, which is configured by the programmatic API.
Autofac’s XML configuration has support for modules, so once you’ve decided to use one in an applicaiton, you can register the module (rather than all the components it contains) in the config file.
Modules support parameters that can be forwarded to the components inside, e.g. connection strings, URIs, etc.
The documentation here should get you started: http://code.google.com/p/autofac/wiki/StructuringWithModules
HTH
Nick