title: Environment variables configuration in .NET Core
body: <p>I'm using the .NET Core 1.1 in my API and am struggling with a problem:</p>
  
  <ol>
  <li>I need to have two levels of configurations: <code>appsettings.json</code> and environment variables.</li>
  <li>I want to use the <a href="https://en.wikipedia.org/wiki/Dependency_injection" rel="noreferrer">DI</a> for my configurations via <code>IOptions</code>.</li>
  <li>I need environment variables to override <code>appsettings.json</code> values.</li>
  </ol>
  
  <p>So I do it like this so far:</p>
  
  <pre><code>public Startup(IHostingEnvironment env)
  {
      var builder = new ConfigurationBuilder()
                  .SetBasePath(env.ContentRootPath)
                  .AddJsonFile("appsettings.json", optional: false, reloadOnChange: true)
                  .AddEnvironmentVariables();
  }
  
  public IServiceProvider ConfigureServices(IServiceCollection services)
  {
       // Something here
       services.Configure&lt;ConnectionConfiguration&gt;(options =&gt;
              Configuration.GetSection("ConnectionStrings").Bind(options));
       // Something there
  }
  </code></pre>
  
  <p>With my <code>appsettings.json</code> composed like this</p>
  
  <pre><code>{
      "ConnectionStrings": {
          "ElasticSearchUrl": "http://localhost:4200",
          "ElasticSearchIndexName": "myindex",
          "PgSqlConnectionString": "blablabla"
      }
  }
  </code></pre>
  
  <p>I get all the configurations mapped to my class <code>ConnectionConfiguration.cs</code>. But I cannot get the environment variables to be mapped as well. I tried the names like: <code>ConnectionStrings:ElasticSearchUrl</code>, <code>ElasticSearchUrl</code>, even tried specifying the prefix to <code>.AddEnvironmentVariables("ConnectionStrings")</code> without any result.</p>
  
  <p>How should I name the environment variables so it can be mapped with <code>services.Configure&lt;TConfiguration&gt;()</code>?</p>