title: How do I bind a multi level configuration object using IConfiguration in a .net Core application?
body: <p>I'm trying to bind to a custom configuration object which should be populated by an appsettings.json file.</p>
  
  <p>My appsettings looks a bit like:</p>
  
  <pre><code>{
    "Logging": {
      "IncludeScopes": true,
      "LogLevel": {
        "Default": "Debug",
        "System": "Information",
        "Microsoft": "Information"
      }
    },
    "Settings": {
      "Foo": {
        "Interval": 30,
        "Count": 10
      }
    }
  }
  </code></pre>
  
  <p>The settings classes look like:</p>
  
  <pre><code>public class Settings
  {
    public Foo myFoo {get;set;}
  }
  
  public class Foo
  {
    public int Interval {get;set;}
    public int Count {get;set;}
  
    public Foo()
    {}
  
    // This is used for unit testing. Should be irrelevant to this question, but included here for completeness' sake.
    public Foo(int interval, int count)
    {
      this.Interval = interval;
      this.Count = count;
    }
  }
  </code></pre>
  
  <p>When I try to bind the Configuration to an object the lowest level it works:</p>
  
  <pre><code>Foo myFoo = Configuration.GetSection("Settings:Foo").Get&lt;Foo&gt;();
  </code></pre>
  
  <p><code>myFoo</code> correctly has an <code>Interval</code> and a <code>Count</code> with values set to 30 and 10 respectively.</p>
  
  <p>But this doesn't:</p>
  
  <pre><code>Settings mySettings = Configuration.GetSection("Settings").Get&lt;Settings&gt;();
  </code></pre>
  
  <p><code>mySettings</code> has a null <code>foo</code>.</p>
  
  <p>Frustratingly, if I use the debugger I can see that the necessary data <em>is</em> being read in from the appsettings.json file. I can step down into <code>Configuration =&gt; Non-Public Members =&gt; _providers =&gt; [0] =&gt; Data</code> and see all of the information I need. It just won't bind for a complex object.</p>