ConfigInjector 1.1 has just been released.
It now supports static loading of individual settings so you can grab settings directly from your app/web.config files without using the dreaded magic strings of ConfigurationManager.AppSettings.
This is a necessary feature but please give some serious thought to whether it’s a good idea in your particular case. If you genuinely need access to settings before your container is wired up, go ahead. If you’re using ConfigInjector as a settings service locator across your entire app, you’re holding it wrong :)
Here’s how:
var setting = DefaultSettingsReader.Get<SimpleIntSetting>();
ConfigInjector will make an intelligent guess at defaults. It will, for instance, walk the call stack that invoked it and look for assemblies that contain settings and value parsers. If you have custom value parsers it will pick those up, too, provided that they’re not off in a satellite assembly somewhere.
If you need to globally change the default behaviour, create a class that implements IStaticSettingReaderStrategy:
public class MyCustomSettingsReaderStrategy : IStaticSettingReaderStrategy
{
// ...
}
and use use this to wire it up:
DefaultSettingsReader.SetStrategy(new MyCustomSettingsReaderStrategy());
If you’re using ConfigInjector and like it, please let me know. There’s Disqus below and there’s always Twitter :)