From e5c6f71155ba4a2c63f90e23bdad7783dfb6c7f5 Mon Sep 17 00:00:00 2001 From: zedy Date: Mon, 12 Dec 2022 14:57:57 +0800 Subject: [PATCH] eliminate manually update the appsettings.json file --- infra/core/database/sqlserver/sqlserver.bicep | 1 + infra/main.bicep | 8 ++++++-- src/Infrastructure/Dependencies.cs | 4 ++-- 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/infra/core/database/sqlserver/sqlserver.bicep b/infra/core/database/sqlserver/sqlserver.bicep index 821a908..1c4c212 100644 --- a/infra/core/database/sqlserver/sqlserver.bicep +++ b/infra/core/database/sqlserver/sqlserver.bicep @@ -127,3 +127,4 @@ resource keyVault 'Microsoft.KeyVault/vaults@2022-07-01' existing = { var connectionString = 'Server=${sqlServer.properties.fullyQualifiedDomainName}; Database=${sqlServer::database.name}; User=${appUser}' output connectionStringKey string = connectionStringKey output databaseName string = sqlServer::database.name +output connectionString string = connectionString diff --git a/infra/main.bicep b/infra/main.bicep index 1d8bba8..535ded5 100644 --- a/infra/main.bicep +++ b/infra/main.bicep @@ -15,9 +15,9 @@ param location string // } param resourceGroupName string = '' param webServiceName string = '' -param catalogDatabaseName string = '' +param catalogDatabaseName string = 'catalogDatabase' param catalogDatabaseServerName string = '' -param identityDatabaseName string = '' +param identityDatabaseName string = 'identityDatabase' param identityDatabaseServerName string = '' param appServicePlanName string = '' param keyVaultName string = '' @@ -55,6 +55,10 @@ module web './core/host/appservice.bicep' = { runtimeName: 'dotnetcore' runtimeVersion: '6.0' tags: union(tags, { 'azd-service-name': 'web' }) + appSettings: { + CATALOG_CONNECTION_STRING_VALUE: '${catalogDb.outputs.connectionString}; Password=${appUserPassword}' + IDENTITY_CONNECTION_STRING_VALUE: '${identityDb.outputs.connectionString}; Password=${appUserPassword}' + } } } diff --git a/src/Infrastructure/Dependencies.cs b/src/Infrastructure/Dependencies.cs index d049a96..d399531 100644 --- a/src/Infrastructure/Dependencies.cs +++ b/src/Infrastructure/Dependencies.cs @@ -30,11 +30,11 @@ public static class Dependencies // Requires LocalDB which can be installed with SQL Server Express 2016 // https://www.microsoft.com/en-us/download/details.aspx?id=54284 services.AddDbContext(c => - c.UseSqlServer(configuration.GetConnectionString("CatalogConnection"))); + c.UseSqlServer(configuration["CATALOG_CONNECTION_STRING_VALUE"])); // Add Identity DbContext services.AddDbContext(options => - options.UseSqlServer(configuration.GetConnectionString("IdentityConnection"))); + options.UseSqlServer(configuration["IDENTITY_CONNECTION_STRING_VALUE"])); } } }