How to Make Strongly-typed References to Web.Config? Let's say I have a configuration file with a property in it:

&lt;add key="LoadedCode" value="L" /&gt;


I know I can reference this using the ConfigurationManager:

System.Configuration.ConfigurationManager.AppSettings["LoadedCode"];


This has some drawbacks.  It can get bulky when it gets used in multiple locations.  I lose support for refactoring and "Find All References" because I'm using an item in the AppSettings collection.  I don't have strong-typing in cases where the config setting isn't a string.  So I wrap it into a static property in a static class:

public static string LoadedCode
{
    get { return System.Configuration.ConfigurationManager.AppSettings["LoadedCode"]; }
}


Great so far.  Now I want to use this on multiple pages and this leads me to my conundrum.  Should I reference this static property everywhere, or should each page have its own local wrapper?

On the one hand, a local wrapper pushes all uses on the page through a single point which can be modified without impacting other pages if needed.  On the other hand, it adds a layer of indirection to the dependency chain and it looks a bit like overkill.  

Is there a best practice for this type of behavior, or am I simply over-thinking things?
I don't do much asp.net, but if this StackOverflow answer applies then you could just do this:

using Settings = MyProject.Namespace.Properties.Settings;

var loadedCode = Settings.Default.LoadedCode;


Like this other StackOverflow answer is saying:


  We prefer to use Properties.Settings (aka. settings.settings) because it's strongly typed.


Now I know for a fact that this works with an app.config, but it might not work with a web.config file... but I think it's worth trying.



Alternatively, this Haacked article describes how to use the configuration API to define your own ConfigurationSection classes, which would be the ultimate way to address this issue. Might be overkill if the above works though.