title: What's the best method to access configuration in .NET 6?
body: <p>The second answer of this question: <a href="https://stackoverflow.com/questions/69722872/asp-net-core-6-how-to-access-configuration-during-startup">ASP.NET Core 6 how to access Configuration during startup</a> mentioned that we can access configuration in this way:</p>
  <blockquote>
  <p>A nice feature worth considering it to create a class that represents your settings and then bind the configuration to an instance of that class type. For example, let's assume you create a new class called MyAppSettings with the same structure as your appSettings.json, you can do the following:</p>
  </blockquote>
  <pre><code>var myAppSettings = builder.Configuration.Get&lt;MyAppSettings&gt;();
  string logLevel = myAppSettings.Logging.LogLevel.Default;
  </code></pre>
  <p>I am confused about it and I want to know how to do that and what are the benefits of this.</p>
  <p>What's more, the best method to access configuration in .NET 6?</p>
  <hr />
  <p>Explain my question in more detail.
  The appSetting.json file in my project has only one layer like this:</p>
  <pre><code>{
   &quot;name&quot;: &quot;jack&quot;,
   ...1000+,
   &quot;age&quot;: &quot;100&quot;
  }
  </code></pre>
  <p>So I cannot configure it using builder.congiguration.GetSection():</p>
  <pre><code>builder.Services.Configure&lt;XXX&gt;(builder.Configuration.GetSection(&quot;XXX&quot;));
  </code></pre>
  <p>How to configure it at once without changing the structure of appSettings.json?</p>
  <p>thank you again~</p>