I had cause to recently revisit an old ASP.NET application I’d written way back when I was a development newcomer. Digging around the web.config I found the appSettings section:
<add key="systemEmailAddress" value="[email protected]" />
<add key="adminEmailAddress" value="[email protected]" />
<add key="templateDirectory" value="~/admin/templates/" />
<add key="installPath" value="~/admin/" />
You get the idea. There were loads of these, configuring many different aspects of the system. Many should have been configurable by site administrators from some kind of user interface. Technically this is possible – editing the web.config on the fly – but I really wouldn’t recommend it.
Anyway, since then I’ve used this method a number of times, as well as having a Settings database table which stores key/value pairs:
var email = SettingRepository.FindByKey("email");
Or having a Settings table with a single row and columns for each setting to allow it to be mapped to an object:
Settings settings = SettingsRepository.FindFirst();
All three have upsides and downsides but none are particularly satisfying. I’m mulling over which approach to take in my next project which is going to need a fair few of these settings. Which method do you favour? Do you have a fourth way?