All of this works fine except for a couple of tweaks needed to use a custom DbContext. I have ApplicationDbContext, which inherits from IdentityDbContext.
Within Startup.cs, I added an IConfiguration parameter to the Configure and RegisterApplicationComponents methods (one feeds the other of course), then within RegisterApplicationComponents I added:
My API is running in Azure and the IConfiguration gets injected at runtime. Then, within the ApplicationDbContext class, I had to add the following constructor:
public ApplicationDbContext(DbContextOptions<ApplicationDbContext> options, IConfiguration configurationVariable) : base(options)
Within the constructor I call configurationVariable.GetConnectionString("MyConnectionStringName") and assign it to a private string variable "_connectionStringVariable" within the ApplicationDbContextClass. Then added the following override:
protected override void OnModelCreating(ModelBuilder builder)
...which contains a couple of bits specific to my application but most importantly calls base.OnModelCreating(builder). I then added the following override:
protected override void OnConfiguring(DbContextOptionsBuilder builder)
_connectionString = null;
The ApplicationDbContext can then be used by my internal services.
We're a place where coders share, stay up-to-date and grow their careers.
We strive for transparency and don't collect excess data.