NuGet/NuGetGallery — Issue #142: Store configuration settings in the database
Author: Haacked
Created: 2011-10-22 17:19:06+00:00
State: open

I added a new `GallerySetting` class so we could store config settings in the database and would like to integrate it into our existing configuration system.

Sounds simple, but there's a couple of questions about how I can go about it.

Right now, we have a Configuration class that looks in 2 places for settings, Azure settings and then in Web.config `appSettings` . Currently, it's just a loose dictionary. Here's an example property.

public string SmtpUsername { get { return ReadConfiguration("SmtpUsername"); } }

Notice that `ReadConfiguration` takes a string and simply looks for that string in a couple places and when it finds it, it adds it to a dictionary (`Dictionary> configThunks`) so the lookups don't have to happen again.

So I'm thinking I'll just simply inject the `GallerySetting` instance into `Configuration` (probably using `Lazy`) and then reading each property like so:

public string SmtpUsername { get {
return _gallerySetting.Value.SmtpUsername ?? ReadConfiguration("SmtpUsername"); }
}

Some properties don't return simple types, so those cases might be a little trickier.

public MailAddress GalleryOwnerEmailAddress {
get {
return ReadConfiguration(
"GalleryOwnerEmail",
(value) => new MailAddress(_gallerySetting.Value.GalleryOwnerEmail ?? value));
}
}

An alternative approach I could take is to use reflection over the GallerySettings instance and add every setting to the _configThunks dictionary ahead of time.

That has the following benefits:
* None of the existing properties has to change.
* Writing a new config property remains relatively simple. No need to worry about _gallerySettings.

Thoughts?