title: How to get ConnectionString from appsettings.json file?
body: <p>the question is how to get the ConnectionString from appsetting.json file in ASP NET Core 3.1 application?
  Here is the appsetings.json file</p>
  <pre><code>&quot;ConnectionStrings&quot;: {
  &quot;DefaultConnection&quot;: &quot;data source=exmaple;initial catalog=example;persist security info=True;user id=example;password=example&quot;
  }
  </code></pre>
  <p>In the example, all parameters are hidden behind the names example</p>
  <p>In the Program.cs class, I include files</p>
  <pre><code>static void ConfigureAppConfiguration(WebHostBuilderContext context, IConfigurationBuilder config, string[] args)
  {
      config
           .AddJsonFile(&quot;appsettings.json&quot;, optional: true, reloadOnChange: true)
           .AddJsonFile($&quot;appsettings.{context.HostingEnvironment.EnvironmentName.ToLowerInvariant()}.json&quot;, optional: true, reloadOnChange: true)
           .AddEnvironmentVariables()
           .AddCommandLine(args);
  }
  </code></pre>
  <p>and when I try to get the connection string values in the Startup class, I get null</p>
  <pre><code>public void ConfigureServices(IServiceCollection services)
  {
      var connetctionString = config.GetConnectionString(&quot;DefaultConnection&quot;);
      ...
  }
  </code></pre>
  <p>Why connection == null ?</p>