title: Auto-generate a strongly-typed AppSettings class
body: <p><strong>Here's the question first:</strong></p>
  
  <p>Is this possible? I'm taking my inspiration from <a href="http://weblogs.asp.net/joewrobel/archive/2008/02/03/web-profile-builder-for-web-application-projects.aspx" rel="nofollow noreferrer" title="Web Profile Builder for Web Application Projects">Joe Wrobel's work</a> (a redux of the forgotten <a href="http://www.codeplex.com/WebProfile" rel="nofollow noreferrer" title="ASP.NET WebProfile Generator">Codeplex project</a>). Here, you do your work on creating your profile for the provider, and it does the legwork of creating the strong typing for it, effectively creating a facade for the Profile class.</p>
  
  <p><strong>And now the back story!</strong></p>
  
  <p>I really don't like <a href="http://en.wikipedia.org/wiki/Magic_string_(programming)" rel="nofollow noreferrer" title="Magic strings @ Wikipedia">magic strings</a>. They're pretty bad and can cause some serious issues when it comes to updating your application. Having worked in languages like PHP and ColdFusion, I know that it's easy to put them into your application and forget about them until you need to change one. And then you have to hunt each and every variation of them down and alter them accordingly.</p>
  
  <p>.NET really isn't that much better if you follow the 'out of the box' application templates. Lots of examples out there use the appsettings in the web.config to store various settings. This is indeed a fine place to store, and is perfect for most applications. Problems start to arise however, when you start calling these directly - for example <code>ConfigurationManager.AppSettings["MyAppSetting"]</code>. Then you're not really any better off than a PHP user as you're back to using magic strings.</p>
  
  <p>This is where <a href="http://en.wikipedia.org/wiki/Facade_pattern" rel="nofollow noreferrer" title="Facade pattern @ Wikipedia">facades</a> come in. Facades offer a way of creating a strongly-typed object from a magic string in one place, and having the developer reference that from the rest of the application.</p>
  
  <p>Now, instead of using a web.config to contain my appsettings, I use a database to hold them all. On application start, the name/value combos are retrieved, and are then sequentially added to the <code>ConfigurationManager.AppSettings</code> via <code>Set</code>. No biggie (apart from the <a href="https://stackoverflow.com/questions/1582198/problems-retrieving-appsettings-added-during-application-start" title="Problems retrieving appsettings added during application start">problem</a> I had earlier!).</p>
  
  <p>This 'application facade' is accessible by my data layer, service layer and presentation layer and holds things like the application mode, which service endpoint to use yada yada yada and limits the need for having to hunt for many magic strings, down to two magic strings - one (the name) in the facade, and the other (the name and value) in the point of creation (which, for me is the db).</p>
  
  <p>This facade class will eventually get pretty big and I'll eventually get tired of having to update both of them.</p>
  
  <p>So what I'd like to do is have an ApplicationFacade class which auto-generates every time a build is done. And now back to the beginning... Is this possible?</p>