title: Access DB Context in program.cs
body: <p>Is there a way to access the DB context of a .NET Core application in the <code>program.cs</code> file? I am basically looking to configure Kestrel with specific options that are stored in the database so I would need access to the database context.</p>
  
  <p>I am basically trying to do something like this:</p>
  
  <pre><code>WebHost.CreateDefaultBuilder(args)
              .UseStartup&lt;Startup&gt;()
              .UseSentry()
              .UseKestrel(opts =&gt;
                   {
                      opts.Listen(IPAddress.Any, 443, listenOptions =&gt;
                      {
                          var storedCert = _db.Certificates.First(c =&gt; c.Id == 1);
                          var certBytes = Convert.FromBase64String(storedCert.CertificatePfx);
                          var certPassword = storedCert.CertificatePassword;
  
                          var cert = new X509Certificate2(certBytes, certPassword);
  
                          listenOptions.UseHttps(cert);
                      });
                  });
  </code></pre>