Playing Chicken With Common Sense

I have not updated my code to the latest Castle Windsor.  I am still using the the previous version.  With it you can setup your .config files to be parsed automatically and stored for you.  All you have to do is setup an interface and initialize a class.  From that point on if you need to add anything to your storage (app.config or web.config) you just have to update the interface.


I created a short demo to show how this works.


Start by creating a new C# console application.  I named mine AutoStorage.  Get a copy of Castle.Components.DictionaryAdapter.dll and make a reference to it from the project.  Now your project is setup and ready.

  1. Add an App.Config to your project
    • Add some values to it as follows: <add key="ApplicationId" value="9F4C7485-AAFC-4929-ADF0-D40B49AC994E" />
  2. <?xml version="1.0" encoding="utf-8" ?>

    <add key="ApplicationId" value="9F4C7485-AAFC-4929-ADF0-D40B49AC994E"/>
    <add key="ApplicationUrl" value="http://localhost/AutoStorage/ApplicationService.asmx"/>


  3. Add an Interface to your project (mine was IStorage.cs)
  4. using System;

    namespace AutoStorage
    public interface IStorage
    string ApplicationId { get; set; }
    string ApplicationUrl { get; set; }

  5. Initialize a DictionaryFactoryAdapter of type IStorage and pass it ConfigurationManager.AppSettings.
    • public static readonly IStorage _storage = new DictionaryAdapterFactory().GetAdapter<IStorage>(ConfigurationManager.AppSettings);
  6. Now write out the values to the command line.
  7. using System;
    using System.Configuration;
    using Castle.Components.DictionaryAdapter;

    namespace AutoStorage
    public class Program
    public static readonly IStorage _storage = new DictionaryAdapterFactory().GetAdapter<IStorage>(ConfigurationManager.AppSettings);

    static void Main(string[] args)
    Console.WriteLine(" ApplicationId: {0}", _storage.ApplicationId);
    Console.WriteLine("ApplicationUrl: {0}", _storage.ApplicationUrl);



That’s it I promise.  There is nothing to it.  Thanks Castle Windsor.  You are my hero.  Also, if you know how to do this same thing using the latest CW then let me know please.  I haven't looked at the newer one yet but I will soon and when I do I will let you know how.

References: DictionaryAdapter API


Download: AutoStorage (44.05 kb)


  • E-mail
  • Kick it!
  • Shout it
  • Bookmark and Share

Control panel


Comment RSS