title: Ways of keeping configuration code out of logic code using Dependency Injection
body: <p>How can keep all the configuration file code out of my logic code using Settings (ApplicationSettingsBase) and Dependency Injection?</p>
  
  <p>With configuration I mean a customer specific configuration file.</p>
  
  <p>Do I really have to inject a configuration class everytime I need it or is there another pattern?</p>
  
  <p>It would be great to get some sample code!</p>
  
  <p>Samples:</p>
  
  <p><strong>Static Configuration:</strong></p>
  
  <pre><code>public static class StaticConfiguration
  {
      public static bool ShouldApplySpecialLogic { get; set; }
      public static string SupportedFileMask { get; set; }
  }
  
  public class ConsumerOfStaticConfiguration
  {
      public void Process()
      {
          if (StaticConfiguration.ShouldApplySpecialLogic)
          {
              var strings = StaticConfiguration.SupportedFileMask.Split(',');
              foreach (var @string in strings)
              {
  
              }
          }
      }
  }
  </code></pre>
  
  <p><strong>Non static Configuration:</strong></p>
  
  <pre><code>public interface IConfiguration
  {
      bool ShouldApplySpecialLogic { get; set; }
      string SupportedFileMask { get; set; }
  }
  
  public class Configuration : IConfiguration
  {
      public bool ShouldApplySpecialLogic { get; set; }
      public string SupportedFileMask { get; set; }
  }
  
  public class Consumer
  {
      private readonly IConfiguration _configuration;
  
      public Consumer(IConfiguration configuration)
      {
          _configuration = configuration;
      }
  
      public void Process()
      {
          if (_configuration.ShouldApplySpecialLogic)
          {
              var strings = _configuration.SupportedFileMask.Split(',');
              foreach (var @string in strings)
              {
  
              }
          }
      }
  }
  </code></pre>
  
  <p><strong>Static Context with non static configuration:</strong></p>
  
  <pre><code>public static class Context
  {
      public static IConfiguration Configuration { get; set; }
  }
  
  public class ConsumerOfStaticContext
  {
      public void Process()
      {
          if (Context.Configuration.ShouldApplySpecialLogic)
          {
              var strings = Context.Configuration.SupportedFileMask.Split(',');
              foreach (var @string in strings)
              {
  
              }
          }
      }
  }
  </code></pre>