title: Access ASP.net Core appsettings.json from an included class library?
body: <p>So I have a .net Core Web Api project and my DBAccess class library included in my solution as a separate project.</p>
  
  <p>inside appsettings.json:</p>
  
  <pre><code>{
    "ConnectionStrings": {
      "DefaultConnection": "Password=L3tters&amp;#s;Persist Security Info=True;User ID=Some_User;Initial Catalog=My_Cat;Data Source=Mt.Shasta"
    },
    "Logging": {
      "IncludeScopes": false,
      "LogLevel": {
        "Default": "Debug",
        "System": "Information",
        "Microsoft": "Information"
      }
    }
  }
  </code></pre>
  
  <p>In startup.cs I have this:</p>
  
  <pre><code>public Startup(IHostingEnvironment env)
          {
              var builder = new ConfigurationBuilder()
                  .SetBasePath(env.ContentRootPath)
                  .AddJsonFile("appsettings.json", optional: true, reloadOnChange: true)
                  .AddJsonFile($"appsettings.{env.EnvironmentName}.json", optional: true)
                  .AddEnvironmentVariables();
              Configuration = builder.Build();
  
          }
  public IConfigurationRoot Configuration { get; }    
  
          public void ConfigureServices(IServiceCollection services)
          {
  
              services.AddMvc();
  
              services.Configure&lt;IISOptions&gt;(options =&gt;
              {
              });
  
              services.AddSingleton&lt;IConfiguration&gt;(Configuration);    
  
          }    
  
            public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
          {
              loggerFactory.AddConsole(Configuration.GetSection("Logging"));
              loggerFactory.AddDebug();
  
              app.UseDefaultFiles();
              app.UseStaticFiles();
              app.UseMvc();
          }
  </code></pre>
  
  <p>So, in controllers I can do stuff like this:</p>
  
  <pre><code>private readonly string _connectionString;
  
          public FloorController(IConfiguration configuration)
          {
              _connectionString = configuration.GetConnectionString("DefaultConnection");
          }
  
  _connectionString = configuration.GetConnectionString("DefaultConnection");
  </code></pre>
  
  <p>All those goodies are in SNC_GSS:</p>
  
  <p><a href="https://i.stack.imgur.com/rGYQg.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/rGYQg.png" alt="Solution Explorer Snip"></a></p>
  
  <p>But I need to get at the settings from DBAccess...
  I'd like to create a reference to SNC_GSS but I can't because SNC_GSS already has a reference to DBAccess and it'd create a circular ref...</p>
  
  <p>Thoughts?</p>