title: Why is the IConfiguration object null after injecting it to DbContext? [ASP.NET Core 3.1]
body: <p>Before posting this question I have gone through multiple posts that are similar. My question focuses on &quot;why is it happening despite applying the common and possibly right solution?&quot;.</p>
  <p>I am developing a .NET Core 3.1 web app. I have a DbContext named 'SkipQContext'. I am trying to access the connection string from <code>appsettings.json</code> in the <code>SkipQContext</code> file using <code>Configuration</code> object.</p>
  <p>For that, I have injected <code>IConfiguration</code> as a service to the <code>SkipQContext</code> constructor.</p>
  <p><strong>Constructor:</strong></p>
  <pre><code>private readonly string ConnectionString;
  
  public SkipQContext()
  { 
  }
  
  public SkipQContext(DbContextOptions&lt;SkipQContext&gt; options, IConfiguration configuration)
      : base(options)
  {
      ConnectionString = configuration.GetConnectionString(&quot;DefaultConnection&quot;);
  }
  </code></pre>
  <p>I have also registered in <strong>ConfigureServices</strong> method of <code>Startup</code> class.</p>
  <pre><code>services.AddSingleton(Configuration);
  </code></pre>
  <p>Now when I instantiate <code>SkipQContext</code> in one of my repository classes, the default constructor of <code>SkipQContext</code> is called. When I try to fetch data using it, I get the &quot;IConfiguration object is null.&quot;</p>
  <p>I applied breakpoints in <code>ConfigureServices</code> method and can see that the <code>IConfiguration</code> object has the connection string value.</p>
  <p>My first question is, why is it null in <code>SkipQContext</code> when I am registering it in <code>ConfigureServices</code> and also injecting it in <code>SkipQContext</code> constructor? Multiple answers online state this as the right method.</p>
  <p>Also, I am thinking, I might not be instantiating the <code>SkipQContext</code> rightly. As my statement :</p>
  <pre><code>SkipQContext db = new SkipQContext();
  </code></pre>
  <p>hits the default constructor of <code>SkipQContext</code> which is empty and not the overloaded constructor where <code>IConfiguration</code> is injected.</p>
  <p>P.S. If the last question is dumb. I am still a bit unclear about how dependency injection works in .NET Core.</p>