title: MVC 6 Configuration Validation
body: <p>In an MVC 6 project, I have the following configuration file...</p>
  
  <pre><code>{
    "ServiceSettings" :
    {
      "Setting1" : "Value"
    }
  }
  </code></pre>
  
  <p>...and the following class...</p>
  
  <pre><code>public class ServiceSettings
  {
    public Setting1
    {
      get;
  
      set;
    }
  }
  </code></pre>
  
  <p>In the <code>ConfigureServices</code> method of the <code>Startup</code> class, I have added the following line of code...</p>
  
  <pre><code>services.Configure&lt;ServiceSettings&gt;(Configuration.GetConfigurationSection("ServiceSettings"));
  </code></pre>
  
  <p>If the value of <code>Setting1</code> is required, how do I validate this?  I could validate at the point the <code>IOptions&lt;ServiceSettings&gt;</code> instance is actually used but if the value of <code>Setting1</code> is necessary for the operation of the service, I would like to catch this as early as possible instead of further downstream.  The old <code>ConfigurationSection</code> object let you specify rules that would throw exceptions at the point the configuration data was read if something was invalid.</p>