From b68bda1b6c1aa761f9ade43d49049233b288d78b Mon Sep 17 00:00:00 2001 From: Niray Date: Fri, 8 Jan 2021 12:45:09 +0100 Subject: [PATCH 1/4] renamed appsettings to fix an issue where API loaded the wrong appsettings in docker environment --- API/Program.cs | 4 ++-- ...s.Development.json => appsettingsapi.Development.json} | 0 API/{appsettings.json => appsettingsapi.json} | 0 NotificationSystem/NotificationSystem.csproj | 8 ++++---- NotificationSystem/Program.cs | 4 ++-- ...son => appsettingsnotificationsystem.Development.json} | 0 ...ppsettings.json => appsettingsnotificationsystem.json} | 0 7 files changed, 8 insertions(+), 8 deletions(-) rename API/{appsettings.Development.json => appsettingsapi.Development.json} (100%) rename API/{appsettings.json => appsettingsapi.json} (100%) rename NotificationSystem/{appsettings.Development.json => appsettingsnotificationsystem.Development.json} (100%) rename NotificationSystem/{appsettings.json => appsettingsnotificationsystem.json} (100%) diff --git a/API/Program.cs b/API/Program.cs index 44b8702b..502417b1 100644 --- a/API/Program.cs +++ b/API/Program.cs @@ -83,8 +83,8 @@ public static IWebHostBuilder CreateHostBuilder(string[] args) .ConfigureAppConfiguration((hostingContext, config) => { IWebHostEnvironment env = hostingContext.HostingEnvironment; - config.AddJsonFile("appsettings.json", true, true) - .AddJsonFile($"appsettings.{env.EnvironmentName}.json", true, true); + config.AddJsonFile("appsettingsapi.json", true, true) + .AddJsonFile($"appsettingsapi.{env.EnvironmentName}.json", true, true); config.AddEnvironmentVariables(); }) .UseSentry() diff --git a/API/appsettings.Development.json b/API/appsettingsapi.Development.json similarity index 100% rename from API/appsettings.Development.json rename to API/appsettingsapi.Development.json diff --git a/API/appsettings.json b/API/appsettingsapi.json similarity index 100% rename from API/appsettings.json rename to API/appsettingsapi.json diff --git a/NotificationSystem/NotificationSystem.csproj b/NotificationSystem/NotificationSystem.csproj index 83e24b50..97180b1b 100644 --- a/NotificationSystem/NotificationSystem.csproj +++ b/NotificationSystem/NotificationSystem.csproj @@ -14,17 +14,17 @@ - - + + - + PreserveNewest true PreserveNewest - + PreserveNewest true PreserveNewest diff --git a/NotificationSystem/Program.cs b/NotificationSystem/Program.cs index 860ff274..0793adb8 100644 --- a/NotificationSystem/Program.cs +++ b/NotificationSystem/Program.cs @@ -14,8 +14,8 @@ private static void Main() { string environmentName = Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT"); IConfiguration configuration = new ConfigurationBuilder() - .AddJsonFile("appsettings.json", true, true) - .AddJsonFile($"appsettings.{environmentName}.json", true, true) + .AddJsonFile("appsettingsnotificationsystem.json", true, true) + .AddJsonFile($"appsettingsnotificationsystem.{environmentName}.json", true, true) .AddEnvironmentVariables() .Build(); Config config = configuration.GetSection("App").Get(); diff --git a/NotificationSystem/appsettings.Development.json b/NotificationSystem/appsettingsnotificationsystem.Development.json similarity index 100% rename from NotificationSystem/appsettings.Development.json rename to NotificationSystem/appsettingsnotificationsystem.Development.json diff --git a/NotificationSystem/appsettings.json b/NotificationSystem/appsettingsnotificationsystem.json similarity index 100% rename from NotificationSystem/appsettings.json rename to NotificationSystem/appsettingsnotificationsystem.json From 774ef088f2f3253992e1581ab7d0aafd490bcaf1 Mon Sep 17 00:00:00 2001 From: Niray Date: Mon, 11 Jan 2021 12:32:52 +0100 Subject: [PATCH 2/4] added comments to make clear why appsettings.json files are renamed. --- API/appsettingsapi.Development.json | 9 +++++---- API/appsettingsapi.json | 2 ++ .../appsettingsnotificationsystem.Development.json | 2 ++ NotificationSystem/appsettingsnotificationsystem.json | 2 ++ 4 files changed, 11 insertions(+), 4 deletions(-) diff --git a/API/appsettingsapi.Development.json b/API/appsettingsapi.Development.json index 1fe18ba2..be60cc5b 100644 --- a/API/appsettingsapi.Development.json +++ b/API/appsettingsapi.Development.json @@ -1,7 +1,8 @@ +// Appsettings is renamed because of an issue where the project loaded another appsettings.json + { "ConnectionStrings": { - "DefaultConnection": - "Server=(LocalDb)\\MSSQLLocalDB;Database=Dex;Trusted_Connection=True;MultipleActiveResultSets=true" + "DefaultConnection": "Server=(LocalDb)\\MSSQLLocalDB;Database=Dex;Trusted_Connection=True;MultipleActiveResultSets=true" }, "App": { "Frontend": { @@ -11,10 +12,10 @@ }, "IdentityServer": { "IdentityUrl": "https://localhost:5005", - "DevelopmentIdentityUrl": "https://localhost:5005" + "DevelopmentIdentityUrl": "https://localhost:5005" }, "Swagger": { - "ClientId": "Swagger-UI" + "ClientId": "Swagger-UI" } }, diff --git a/API/appsettingsapi.json b/API/appsettingsapi.json index 79831161..c119cbb8 100644 --- a/API/appsettingsapi.json +++ b/API/appsettingsapi.json @@ -1,3 +1,5 @@ +// Appsettings is renamed because of an issue where the project loaded another appsettings.json + { "UpdateInstitutionOnLogin": true, "ConnectionStrings": { diff --git a/NotificationSystem/appsettingsnotificationsystem.Development.json b/NotificationSystem/appsettingsnotificationsystem.Development.json index 7abc5389..f5e21961 100644 --- a/NotificationSystem/appsettingsnotificationsystem.Development.json +++ b/NotificationSystem/appsettingsnotificationsystem.Development.json @@ -1,3 +1,5 @@ +// Appsettings is renamed because of an issue where the project loaded another appsettings.json + { "App": { "RabbitMQ": { diff --git a/NotificationSystem/appsettingsnotificationsystem.json b/NotificationSystem/appsettingsnotificationsystem.json index e779e003..0467b99c 100644 --- a/NotificationSystem/appsettingsnotificationsystem.json +++ b/NotificationSystem/appsettingsnotificationsystem.json @@ -1,3 +1,5 @@ +// Appsettings is renamed because of an issue where the project loaded another appsettings.json + { "App": { "RabbitMQ": { From a9ebd77c7dea5846752bda730c8294b54d5fba26 Mon Sep 17 00:00:00 2001 From: Niray Date: Mon, 11 Jan 2021 13:00:50 +0100 Subject: [PATCH 3/4] hardcoded environment variables are now in docker-compose for development purposes. Some people used a .env file where values came from. I think this is better because it take no extra steps to actually run using docker-compose after cloning the project. (unless you want to use SendGrid) --- docker-compose.yml | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/docker-compose.yml b/docker-compose.yml index 77f5b814..464b9dc9 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -5,8 +5,8 @@ services: container_name: rabbitmq image: 'bitnami/rabbitmq:3.8.9' environment: - - RABBITMQ_USERNAME=${App__RabbitMQ__Username} - - RABBITMQ_PASSWORD=${App__RabbitMQ__Password} + - RABBITMQ_USERNAME=test + - RABBITMQ_PASSWORD=test ports: - 5672:5672 - 5671:5671 @@ -55,11 +55,11 @@ services: depends_on: - rabbitmq environment: - - App__RabbitMQ__Hostname=${App__RabbitMQ__Hostname} - - App__RabbitMQ__Username=${App__RabbitMQ__Username} - - App__RabbitMQ__Password=${App__RabbitMQ__Password} - - App__SendGrid__ApiKey=${App__SendGrid__ApiKey} - - App__SendGrid__EmailFrom=${App__SendGrid__EmailFrom} + - App__RabbitMQ__Hostname=rabbitmq + - App__RabbitMQ__Username=test + - App__RabbitMQ__Password=test + - App__SendGrid__ApiKey=test + - App__SendGrid__EmailFrom=test stdin_open: true tty: true networks: @@ -80,9 +80,9 @@ services: - ASPNETCORE_HTTPS_PORT=5001 - ASPNETCORE_Kestrel__Certificates__Default__Password=xI90DrNea7M6UJFNDwip6t - ASPNETCORE_Kestrel__Certificates__Default__Path=/app/dex-api.pfx - - App__RabbitMQ__Hostname=${App__RabbitMQ__Hostname} - - App__RabbitMQ__Username=${App__RabbitMQ__Username} - - App__RabbitMQ__Password=${App__RabbitMQ__Password} + - App__RabbitMQ__Hostname=rabbitmq + - App__RabbitMQ__Username=test + - App__RabbitMQ__Password=test networks: mssql-network: rabbitmq-network: From d95beff111e9b6d3bdd1fe8f0fd57398fd849d6d Mon Sep 17 00:00:00 2001 From: Niray Date: Wed, 13 Jan 2021 13:29:51 +0100 Subject: [PATCH 4/4] removed comments from json, replaced it to program. --- API/Program.cs | 1 + API/appsettingsapi.Development.json | 2 -- API/appsettingsapi.json | 2 -- NotificationSystem/Program.cs | 1 + .../appsettingsnotificationsystem.Development.json | 2 -- NotificationSystem/appsettingsnotificationsystem.json | 2 -- 6 files changed, 2 insertions(+), 8 deletions(-) diff --git a/API/Program.cs b/API/Program.cs index ee814e78..0b61586f 100644 --- a/API/Program.cs +++ b/API/Program.cs @@ -80,6 +80,7 @@ public static int Main(string[] args) /// The webhostbuilder instance. public static IWebHostBuilder CreateHostBuilder(string[] args) { + // Appsettings is renamed because of an issue where the project loaded another appsettings.json return WebHost.CreateDefaultBuilder(args) .UseContentRoot(Directory.GetCurrentDirectory()) .ConfigureAppConfiguration((hostingContext, config) => diff --git a/API/appsettingsapi.Development.json b/API/appsettingsapi.Development.json index be60cc5b..35b52ce8 100644 --- a/API/appsettingsapi.Development.json +++ b/API/appsettingsapi.Development.json @@ -1,5 +1,3 @@ -// Appsettings is renamed because of an issue where the project loaded another appsettings.json - { "ConnectionStrings": { "DefaultConnection": "Server=(LocalDb)\\MSSQLLocalDB;Database=Dex;Trusted_Connection=True;MultipleActiveResultSets=true" diff --git a/API/appsettingsapi.json b/API/appsettingsapi.json index c119cbb8..79831161 100644 --- a/API/appsettingsapi.json +++ b/API/appsettingsapi.json @@ -1,5 +1,3 @@ -// Appsettings is renamed because of an issue where the project loaded another appsettings.json - { "UpdateInstitutionOnLogin": true, "ConnectionStrings": { diff --git a/NotificationSystem/Program.cs b/NotificationSystem/Program.cs index 16063a75..817437b9 100644 --- a/NotificationSystem/Program.cs +++ b/NotificationSystem/Program.cs @@ -14,6 +14,7 @@ internal class Program private static void Main() { string environmentName = Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT"); + // Appsettings is renamed because of an issue where the project loaded another appsettings.json IConfiguration configuration = new ConfigurationBuilder() .AddJsonFile("appsettingsnotificationsystem.json", true, true) .AddJsonFile($"appsettingsnotificationsystem.{environmentName}.json", true, true) diff --git a/NotificationSystem/appsettingsnotificationsystem.Development.json b/NotificationSystem/appsettingsnotificationsystem.Development.json index 54d62bed..be6efb8d 100644 --- a/NotificationSystem/appsettingsnotificationsystem.Development.json +++ b/NotificationSystem/appsettingsnotificationsystem.Development.json @@ -1,5 +1,3 @@ -// Appsettings is renamed because of an issue where the project loaded another appsettings.json - { "App": { "RabbitMQ": { diff --git a/NotificationSystem/appsettingsnotificationsystem.json b/NotificationSystem/appsettingsnotificationsystem.json index 8f830a6e..186327d4 100644 --- a/NotificationSystem/appsettingsnotificationsystem.json +++ b/NotificationSystem/appsettingsnotificationsystem.json @@ -1,5 +1,3 @@ -// Appsettings is renamed because of an issue where the project loaded another appsettings.json - { "App": { "RabbitMQ": {