From 66023ba71c353af4f8e84e383d250f6fe878cf97 Mon Sep 17 00:00:00 2001 From: Kurban Kurbanov Date: Sun, 5 May 2024 02:00:05 +0300 Subject: [PATCH 1/4] add environment --- AuthenticationService/AuthenticationService.csproj | 7 +++++++ AuthenticationService/Program.cs | 5 +++++ AuthenticationService/appsettings.Development.json | 3 +++ AuthenticationService/appsettings.Production.json | 11 +++++++++++ AuthenticationService/appsettings.Test.json | 11 +++++++++++ AuthenticationService/appsettings.json | 9 --------- AuthenticationService/dockerfile | 2 +- 7 files changed, 38 insertions(+), 10 deletions(-) create mode 100644 AuthenticationService/appsettings.Production.json create mode 100644 AuthenticationService/appsettings.Test.json diff --git a/AuthenticationService/AuthenticationService.csproj b/AuthenticationService/AuthenticationService.csproj index 022ca01..77a211d 100644 --- a/AuthenticationService/AuthenticationService.csproj +++ b/AuthenticationService/AuthenticationService.csproj @@ -15,4 +15,11 @@ + + + + + + + diff --git a/AuthenticationService/Program.cs b/AuthenticationService/Program.cs index 6db4fc6..dc5cfa5 100644 --- a/AuthenticationService/Program.cs +++ b/AuthenticationService/Program.cs @@ -11,6 +11,11 @@ public static void Main(string[] args) var builder = WebApplication.CreateBuilder(args); // Add services to the container. + builder.Configuration + .AddJsonFile("appsettings.json", false, true) + .AddJsonFile($"appsettings.{builder.Environment.EnvironmentName}.json", false, true) + .AddEnvironmentVariables(); + var connectionString = builder.Configuration.GetConnectionString("DefaultConnection") ?? throw new InvalidOperationException("Connection string 'DefaultConnection' not found."); builder.Services.AddDbContext(options => options.UseSqlServer(connectionString)); diff --git a/AuthenticationService/appsettings.Development.json b/AuthenticationService/appsettings.Development.json index 0c208ae..5fe1f07 100644 --- a/AuthenticationService/appsettings.Development.json +++ b/AuthenticationService/appsettings.Development.json @@ -1,4 +1,7 @@ { + "ConnectionStrings": { + "DefaultConnection": "Server=(localdb)\\mssqllocaldb;Database=aspnet-AuthenticationService-1db18c2e-a289-4d23-b83a-1675d921f49b;Trusted_Connection=True;MultipleActiveResultSets=true" + }, "Logging": { "LogLevel": { "Default": "Information", diff --git a/AuthenticationService/appsettings.Production.json b/AuthenticationService/appsettings.Production.json new file mode 100644 index 0000000..aee69c2 --- /dev/null +++ b/AuthenticationService/appsettings.Production.json @@ -0,0 +1,11 @@ +{ + "ConnectionStrings": { + "DefaultConnection": "" + }, + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft.AspNetCore": "Warning" + } + } +} \ No newline at end of file diff --git a/AuthenticationService/appsettings.Test.json b/AuthenticationService/appsettings.Test.json new file mode 100644 index 0000000..e0e769c --- /dev/null +++ b/AuthenticationService/appsettings.Test.json @@ -0,0 +1,11 @@ +{ + "ConnectionStrings": { + "DefaultConnection": "Server=(localdb)\\mssqllocaldb;Database=aspnet-AuthenticationService-1db18c2e-a289-4d23-b83a-1675d921f49b;Trusted_Connection=True;MultipleActiveResultSets=true" + }, + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft.AspNetCore": "Warning" + } + } +} \ No newline at end of file diff --git a/AuthenticationService/appsettings.json b/AuthenticationService/appsettings.json index 3da2901..4faf77a 100644 --- a/AuthenticationService/appsettings.json +++ b/AuthenticationService/appsettings.json @@ -1,12 +1,3 @@ { - "ConnectionStrings": { - "DefaultConnection": "Server=(localdb)\\mssqllocaldb;Database=aspnet-AuthenticationService-1db18c2e-a289-4d23-b83a-1675d921f49b;Trusted_Connection=True;MultipleActiveResultSets=true" - }, - "Logging": { - "LogLevel": { - "Default": "Information", - "Microsoft.AspNetCore": "Warning" - } - }, "AllowedHosts": "*" } diff --git a/AuthenticationService/dockerfile b/AuthenticationService/dockerfile index 47936ad..14691a5 100644 --- a/AuthenticationService/dockerfile +++ b/AuthenticationService/dockerfile @@ -8,4 +8,4 @@ FROM mcr.microsoft.com/dotnet/aspnet:8.0 WORKDIR /AuthenticationService COPY --from=base /AuthenticationService/out ./ EXPOSE 8080 -ENTRYPOINT [ "dotnet", "AuthenticationService.dll" ] \ No newline at end of file +ENTRYPOINT [ "dotnet", "AuthenticationService.dll", "--environment=Test" ] \ No newline at end of file From 1a51207d7cf5061441fbe48810c83fdecd55d625 Mon Sep 17 00:00:00 2001 From: Kurban Kurbanov Date: Sun, 5 May 2024 18:31:09 +0300 Subject: [PATCH 2/4] fixed connection string --- AuthenticationService/appsettings.Test.json | 2 +- .../AuthorizationWebApplication.csproj | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/AuthenticationService/appsettings.Test.json b/AuthenticationService/appsettings.Test.json index e0e769c..0bec7df 100644 --- a/AuthenticationService/appsettings.Test.json +++ b/AuthenticationService/appsettings.Test.json @@ -1,6 +1,6 @@ { "ConnectionStrings": { - "DefaultConnection": "Server=(localdb)\\mssqllocaldb;Database=aspnet-AuthenticationService-1db18c2e-a289-4d23-b83a-1675d921f49b;Trusted_Connection=True;MultipleActiveResultSets=true" + "DefaultConnection": "Server=(localdb)\\MSSQLLocalDB;Database=Authorization;Trusted_Connection=true;" }, "Logging": { "LogLevel": { diff --git a/AuthorizationWebApplication/AuthorizationWebApplication.csproj b/AuthorizationWebApplication/AuthorizationWebApplication.csproj index 2eaabf0..151349c 100644 --- a/AuthorizationWebApplication/AuthorizationWebApplication.csproj +++ b/AuthorizationWebApplication/AuthorizationWebApplication.csproj @@ -21,4 +21,12 @@ + + + + + + + + From b98053b49b06ad043ff7ff38e448fc6895f1ee87 Mon Sep 17 00:00:00 2001 From: Kurban Kurbanov Date: Sun, 5 May 2024 18:44:05 +0300 Subject: [PATCH 3/4] change configs --- AuthenticationService/appsettings.Development.json | 3 --- AuthenticationService/appsettings.Production.json | 10 +--------- 2 files changed, 1 insertion(+), 12 deletions(-) diff --git a/AuthenticationService/appsettings.Development.json b/AuthenticationService/appsettings.Development.json index 5fe1f07..0c208ae 100644 --- a/AuthenticationService/appsettings.Development.json +++ b/AuthenticationService/appsettings.Development.json @@ -1,7 +1,4 @@ { - "ConnectionStrings": { - "DefaultConnection": "Server=(localdb)\\mssqllocaldb;Database=aspnet-AuthenticationService-1db18c2e-a289-4d23-b83a-1675d921f49b;Trusted_Connection=True;MultipleActiveResultSets=true" - }, "Logging": { "LogLevel": { "Default": "Information", diff --git a/AuthenticationService/appsettings.Production.json b/AuthenticationService/appsettings.Production.json index aee69c2..0e0dcd2 100644 --- a/AuthenticationService/appsettings.Production.json +++ b/AuthenticationService/appsettings.Production.json @@ -1,11 +1,3 @@ { - "ConnectionStrings": { - "DefaultConnection": "" - }, - "Logging": { - "LogLevel": { - "Default": "Information", - "Microsoft.AspNetCore": "Warning" - } - } + } \ No newline at end of file From f58217789f7ac16ecf2bf12ccd59f67f37e084c1 Mon Sep 17 00:00:00 2001 From: Kurban Kurbanov Date: Sun, 5 May 2024 18:44:51 +0300 Subject: [PATCH 4/4] added confir for prod --- AuthenticationService/appsettings.Production.json | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/AuthenticationService/appsettings.Production.json b/AuthenticationService/appsettings.Production.json index 0e0dcd2..aee69c2 100644 --- a/AuthenticationService/appsettings.Production.json +++ b/AuthenticationService/appsettings.Production.json @@ -1,3 +1,11 @@ { - + "ConnectionStrings": { + "DefaultConnection": "" + }, + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft.AspNetCore": "Warning" + } + } } \ No newline at end of file