fix possible null reference error

This commit is contained in:
zedy
2023-08-11 13:30:14 +08:00
parent b2ea136f30
commit d2753c7d68

View File

@@ -34,15 +34,15 @@ if (detectEnvApp.Environment.IsDevelopment() || detectEnvApp.Environment.Environ
else{ else{
// Configure SQL Server (prod) // Configure SQL Server (prod)
var credential = new ChainedTokenCredential(new AzureDeveloperCliCredential(), new DefaultAzureCredential()); var credential = new ChainedTokenCredential(new AzureDeveloperCliCredential(), new DefaultAzureCredential());
builder.Configuration.AddAzureKeyVault(new Uri(builder.Configuration["AZURE_KEY_VAULT_ENDPOINT"]), credential); builder.Configuration.AddAzureKeyVault(new Uri(builder.Configuration["AZURE_KEY_VAULT_ENDPOINT"] ?? ""), credential);
builder.Services.AddDbContext<CatalogContext>(c => builder.Services.AddDbContext<CatalogContext>(c =>
{ {
var connectionString = builder.Configuration[builder.Configuration["AZURE_SQL_CATALOG_CONNECTION_STRING_KEY"]]; var connectionString = builder.Configuration[builder.Configuration["AZURE_SQL_CATALOG_CONNECTION_STRING_KEY"] ?? ""];
c.UseSqlServer(connectionString, sqlOptions => sqlOptions.EnableRetryOnFailure()); c.UseSqlServer(connectionString, sqlOptions => sqlOptions.EnableRetryOnFailure());
}); });
builder.Services.AddDbContext<AppIdentityDbContext>(options => builder.Services.AddDbContext<AppIdentityDbContext>(options =>
{ {
var connectionString = builder.Configuration[builder.Configuration["AZURE_SQL_IDENTITY_CONNECTION_STRING_KEY"]]; var connectionString = builder.Configuration[builder.Configuration["AZURE_SQL_IDENTITY_CONNECTION_STRING_KEY"] ?? ""];
options.UseSqlServer(connectionString, sqlOptions => sqlOptions.EnableRetryOnFailure()); options.UseSqlServer(connectionString, sqlOptions => sqlOptions.EnableRetryOnFailure());
}); });
} }