title: Where to store application settings?
body: <p>Recently, I discovered that the "Web.Config" file contains an <code>&lt;appSettings&gt;</code> section which seemed good for storing one's Application Settings. Heck, it even has a programmatic way to access the file thru a standard System library. So being all clever, I wrote an Interface to access it and then a Concrete implementation of the interface, shown here:</p>
  
  <pre><code>public interface IAppSettings
  {
      IEnumerable&lt;string&gt; GetValues(string componentName, string settingName);
      IEnumerable&lt;KeyValuePair&lt;string, string&gt;&gt; GetValuePairs(string componentName, string settingName);
      void SetValues(string componentName, string settingName, IEnumerable&lt;string&gt; valueList, bool append);
      void SetValuePairs(string componentName, string settingName, IEnumerable&lt;KeyValuePair&lt;string, string&gt;&gt; pairList, bool append);
  }
  </code></pre>
  
  <p>Then I came to discover that <a href="https://stackoverflow.com/questions/3972984/asp-net-httpruntime-cache-getting-flushed-when-saving-webconfigurationmanager">saving settings back to "web.config" while the application is running causes the entire application to re-start</a>. This seems completely unreasonable to me because if I'm writing back to web.config a lot and the application is restarting each time, then things like HttpRuntime.Cache get completely emptied effectively making my Cache useless because it's constantly emptying and repopulating.</p>
  
  <p>So I'm wondering: Where should I store my Application Settings?</p>
  
  <p>Is there a good solution out there for this so that I don't have to roll my own?</p>
  
  <p><strong>EDIT:</strong> </p>
  
  <p>Okay, thanks to everyone who suggested using a DB and a potential table schema. I think I'm going to go with the following schema:</p>
  
  <pre><code>settings:
      index NUMBER NOT NULL AUTO_INCREMENT   &lt;== Primary Key
      component NVARCHAR(255) NOT NULL
      setting NVARCHAR(255) NOT NULL
      key   NVARCHAR(255)
      value NVARCHAR(255) NOT NULL
  </code></pre>
  
  <p>Though I don't think I'll make the "setting" the P-Key, but use an Auto-Incr Index instead. This way if I have an application that needs to mail something to multiple managers, I can store many:</p>
  
  <pre><code>index     component       setting        value
  1         RequestModule   ManagerEmail   manager1@someplace
  2         RequestModule   ManagerEmail   manager2@someplace
  </code></pre>
  
  <p>And then I can use:</p>
  
  <pre><code>IEnumerable&lt;string&gt; GetValues(string componentName, string settingName);
  </code></pre>
  
  <p>And it will return a list of email addresses, rather than just a single value.</p>
  
  <p>Does this make sense?</p>