title: How better to map configuration elements to application objects?
body: <p>I have a .NET application which has a custom configuration to re-construct some classes on startup. That's not a plain (de)serialization, that's more complex and mixed.</p>
  
  <pre><code>class FooElement : ConfigurationElement
  {
       static ConfigurationProperty propValue = new ConfigurationProperty("value", typeof(int));
       static ConfigurationProperty propType = new ConfigurationProperty("type", typeof(string));
  
       [ConfigurationProperty("value")]
       public int Value
       {
           get { return (int)this[propValue] }
           set { this[propValue] = value }
       }
  
       [ConfigurationProperty("type")]
       public string Type
       {
           get { return (int)this[propType] }
           set { this[propType] = value }
       }
  }
  
  class Foo : IFoo
  {
      public int Value { get; set; 
      public string Type { get; set; }
  }
  </code></pre>
  
  <p>Some of configuration elements repeats application objects by properties, but I don't want to use elements in my application, I created light-weight objects for this purpose. Probably I can call them POCOs.</p>
  
  <p>Currently I have next: Config:</p>
  
  <pre><code>&lt;elements&gt;
      &lt;add type="MyProj.Foo, MyProj" value="10" /&gt;
  &lt;/elements&gt;
  </code></pre>
  
  <p>Code:</p>
  
  <pre><code>elements.Select(e =&gt; (IFoo)Activator.CreateInstance(e.Type, e));
  
  public Foo(FooElement element)
  {
      this.Value = element.Value;
  }
  </code></pre>
  
  <p>How to better to do that? Maybe using IoC or something similar.</p>