title: How to map multiple levels of Settings from appsettings.json in .Net 5 (Asp.Net)
body: <p>I am migrating an Asp.Net MVC application to .Net5. I had a static class that served as a façade for the settings in web.config. My Setting class exposed static properties, each one of a class representing settings groups, for example:</p>
  <pre><code>public static class MySettings
  {
      public static class MainDB
      {
          public static string ConnectionString
          {
              get
              {
                  // Code to retrieve the actual values
                  return &quot;&quot;;
              }
          }
      }
  
      public static class ExternalApi
      {
          public static string Uri
          {
              get
              { // Code to retrieve the actual values
                  return &quot;&quot;;
              }
          }
      }
  
      public static class OtherSettings
      {
          // ...
      }
  }
  </code></pre>
  <p>In .Net Core 5 (actually, since .Net Core 2) we use POCO's tyo read settings as depicted in <a href="https://docs.microsoft.com/en-us/aspnet/core/fundamentals/configuration/options?view=aspnetcore-5.0" rel="nofollow noreferrer">https://docs.microsoft.com/en-us/aspnet/core/fundamentals/configuration/options?view=aspnetcore-5.0</a></p>
  <p>Is there any way to map all my settings to one single object, for example, for appsettings.json:</p>
  <pre><code>{
    &quot;Logging&quot;: {
      &quot;LogLevel&quot;: {
        &quot;Default&quot;: &quot;Information&quot;,
        &quot;Microsoft&quot;: &quot;Warning&quot;,
        &quot;Microsoft.Hosting.Lifetime&quot;: &quot;Information&quot;
      }
    },
    &quot;AllowedHosts&quot;: &quot;*&quot;,
    &quot;Settings&quot;: {
      &quot;MainDB&quot;: {
        &quot;ConnectionString&quot;: &quot;whatever needed to access the db&quot;
      },
      &quot;ExtrenaAPI&quot; {
        &quot;Uri&quot;: &quot;https://whatever.api.com&quot;,
        &quot;Key&quot;: &quot;mysupersecretkey&quot;,
        &quot;Secret&quot;: &quot;mysupersecret-uh-secret&quot;
      }
    }
  }
  </code></pre>
  <p>Classes:</p>
  <pre><code>public class MainDB
  {
      public string ConnectionString { get; set; }
  }
  
  public class ExternalApi
  {
      public string Uri { get; set; }
      public string Key { get; set; }
      public string Secret { get; set; }
  }
  
  public class Settings
  {
      public MainDB MainDB { get; set; }
  
      `public ExternalApi ExternalApi { get; set; }
  }
  </code></pre>
  <p>Configuration (in Startup.cs):</p>
  <pre><code>services.Configure&lt;Settings&gt;(Configuration.GetSection(&quot;Settings&quot;));
  </code></pre>
  <p>(Yes, I know I can do <code>services.Configure&lt;MainDB&gt;(Configuration.GetSection(&quot;Settings:MainDB&quot;));</code> and <code>services.Configure&lt;ExternalApi&gt;(Configuration.GetSection(&quot;Settings:ExternalApi&quot;));</code> but I'd like to get all the settings in one sigle object if it is possible.</p>
  <p>Any suggestion?</p>