Entity Framework Core
A lightweight, extensible, open-source, and cross-platform version of the Entity Framework data access technology.
779 questions
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
Hello I am using the following code in my Program.cs
file to successfully retrieve my connection string stored as a secret in Azure Key Vault
(something I can see while debugging). The question I have, is how do I get this value securely to my classes that inherit DbContext
?
Program.cs
var builder = WebApplication.CreateBuilder(args);
var keyVaultEndpoint = new Uri(Environment.GetEnvironmentVariable("VaultUri"));
builder.Configuration.AddAzureKeyVault(keyVaultEndpoint,
new DefaultAzureCredential(new DefaultAzureCredentialOptions
{
ManagedIdentityClientId = builder.Configuration["AzureADManagedIdentityClientId"]
}));
Working to replace the following in my Class "CustomerContext" that inherits DbContext. (Connection string removed, but currently included)
public CustomerContext()
{
//
DbPath = "Data Source...";
}
protected override void OnConfiguring(DbContextOptionsBuilder options)
=> options.UseSqlServer(DbPath);