Been playing around with creating my own configuration section handlers. Call me crazy, but i just have a distaste for storing my hierarchical application configurations in some kind of artificially derived flat Key/Value pair scheme.
I see a lot of applications doing something like:
when it would be so much cleaner to do:
The answer to this is System.Configuration.IConfigurationSectionHandler and then you stuff the result in a singleton. A couple of pitfalls with this approach are:
Application vs. ASP.NET: The singleton needs to determine whether it's running as an application or under ASP.NET, so it can decide whether it needs to be a thread singleton or can just be a static variable. Easiest solution here is to allow a way to manually initialize the singleton with a flag. Then you can use Begin_Request in global.asax to tell it to use a thread singleton and default to a static variable otherwise
Allowing for config relocation like AppSettings: AppSettings lets you externalize your name/value pairs via