title: Global Variables in ASP.Net Core 2.2
body: <p>I'm trying to get more clarification on an already asked question.  Because I'm a new user, I can't comment yet (You must have 50 reputation to comment).</p>
  
  <p>In regards to <a href="https://stackoverflow.com/questions/52654307/global-variables-in-asp-net-core-2">Global Variables in ASP.Net Core 2</a></p>
  
  <p>@nurdyguy comments that "The dependency injection built in to the framework will populate the options variable".  </p>
  
  <pre><code>var repo = new DB();
  </code></pre>
  
  <p>More code to demonstrate the problem:</p>
  
  <pre><code>    public class Secrets
      {
          public string ConnectionString { get; set; }
      }
  
      public class Startup
      {
          public Startup(IConfiguration configuration)
          {
              Configuration = configuration;
          }
  
          public IConfiguration Configuration { get; }
  
          public void ConfigureServices(IServiceCollection services)
          {
              .
              .
              .
  
              System.Action&lt;Secrets&gt; opts = (opt =&gt;
              {
                  opt.ConnectionString = Configuration["ConnectionString"];
              });
              services.Configure(opts);
              services.AddSingleton(resolver =&gt; resolver.GetRequiredService&lt;IOptions&lt;Secrets&gt;&gt;().Value);
          }
      }
  
      public sealed class DB
      {
          private string _connectionString;
  
          public DB(Secrets secrets)
          {
              _connectionString = secrets.ConnectionString;
          }
      }
  
      public class testModel : PageModel
      {
          public void OnGet()
          {
              DB db = new DB();
          }
      }
  </code></pre>
  
  <p>When I attempt to instantiate the class, I receive a the following compile time error:</p>
  
  <p>Error CS7036
  There is no argument given that corresponds to the required formal parameter 'secrets' of 'DB(Secrets)'</p>
  
  <p>I've followed the code example correctly I'm sure.  Is their another way to instantiate the class?</p>