Is there a way to access the DB context of a .NET Core application in the program.cs
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.
I am basically trying to do something like this:
WebHost.CreateDefaultBuilder(args)
.UseStartup<Startup>()
.UseSentry()
.UseKestrel(opts =>
{
opts.Listen(IPAddress.Any, 443, listenOptions =>
{
var storedCert = _db.Certificates.First(c => c.Id == 1);
var certBytes = Convert.FromBase64String(storedCert.CertificatePfx);
var certPassword = storedCert.CertificatePassword;
var cert = new X509Certificate2(certBytes, certPassword);
listenOptions.UseHttps(cert);
});
});