From 2a9fa613906ea9669d989372e9fd92b9655396a5 Mon Sep 17 00:00:00 2001 From: Hamed Shirbandi Date: Thu, 5 Dec 2024 00:48:10 +0100 Subject: [PATCH] refactor: startup services configurations --- .../Configuration/MVC/MvcConfiguration.cs | 32 ++++++++-------- .../MVC/RazorPagesConfiguration.cs | 32 ++++++++-------- .../Configuration/MVC/WebApiConfiguration.cs | 37 ++++++++++--------- src/1-BuildingBlocks/Web.MVC/Web.MVC.csproj | 8 +++- .../Boards/Api/Boards.Read.Api/Program.cs | 2 +- .../Boards/Api/Boards.Read.Api/Startup.cs | 10 ++--- .../Api/Boards.Read.Api/appsettings.json | 15 ++++---- .../Boards/Api/Boards.Write.Api/Program.cs | 2 +- .../Boards/Api/Boards.Write.Api/Startup.cs | 10 ++--- .../Api/Boards.Write.Api/appsettings.json | 15 ++++---- .../Api/Identity.Api/Identity.Api.csproj | 1 + .../Identity/Api/Identity.Api/Program.cs | 2 +- .../Identity/Api/Identity.Api/Startup.cs | 10 ++--- .../Owners/Api/Owners.Read.Api/Program.cs | 2 +- .../Owners/Api/Owners.Read.Api/Startup.cs | 10 ++--- .../Owners/Api/Owners.Write.Api/Program.cs | 2 +- .../Owners/Api/Owners.Write.Api/Startup.cs | 10 ++--- .../Tasks/Api/Tasks.Read.Api/Program.cs | 2 +- .../Tasks/Api/Tasks.Read.Api/Startup.cs | 10 ++--- .../Tasks/Api/Tasks.Write.Api/Program.cs | 2 +- .../Tasks/Api/Tasks.Write.Api/Startup.cs | 10 ++--- .../UserPanel/Aggregator/Program.cs | 2 +- .../UserPanel/Aggregator/Startup.cs | 9 ++--- .../UserPanel/ApiGateway/Program.cs | 2 +- .../UserPanel/ApiGateway/Startup.cs | 10 +---- src/4-Clients/UserPanel/Startup.cs | 3 +- src/4-Clients/Website/Program.cs | 2 +- src/4-Clients/Website/Startup.cs | 9 ++--- 28 files changed, 114 insertions(+), 147 deletions(-) diff --git a/src/1-BuildingBlocks/Web.MVC/Configuration/MVC/MvcConfiguration.cs b/src/1-BuildingBlocks/Web.MVC/Configuration/MVC/MvcConfiguration.cs index 0036dbb03..83e24e61a 100644 --- a/src/1-BuildingBlocks/Web.MVC/Configuration/MVC/MvcConfiguration.cs +++ b/src/1-BuildingBlocks/Web.MVC/Configuration/MVC/MvcConfiguration.cs @@ -1,10 +1,10 @@ using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.Server.Kestrel.Core; -using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Hosting; -using TaskoMask.BuildingBlocks.Web.MVC.Configuration.Metric; +using TaskoMask.BuildingBlocks.Web.MVC.Configuration.Observation.OpenTelemetry; +using TaskoMask.BuildingBlocks.Web.MVC.Configuration.Observation.Serilog; using TaskoMask.BuildingBlocks.Web.MVC.Services.AuthenticatedUser; namespace TaskoMask.BuildingBlocks.Web.MVC.Configuration.MVC; @@ -17,44 +17,44 @@ public static class MvcConfiguration /// /// /// - public static void AddMvcPreConfigured(this IServiceCollection services, IConfiguration configuration) + public static void AddMvcPreConfigured(this WebApplicationBuilder builder) { - if (services == null) - throw new ArgumentNullException(nameof(services)); + ArgumentNullException.ThrowIfNull(builder); - services.AddControllersWithViews(); + builder.AddCustomSerilog(); - services.AddHttpContextAccessor(); + builder.Services.AddControllersWithViews(); - services.AddAuthenticatedUserService(); + builder.Services.AddHttpContextAccessor(); - services.AddWebServerOptions(); + builder.Services.AddAuthenticatedUserService(); - services.AddMetrics(configuration); + builder.Services.AddWebServerOptions(); + + builder.AddOpenTelemetry(); } /// /// /// - public static void UseMvcPreConfigured(this IApplicationBuilder app, IWebHostEnvironment env, IConfiguration configuration) + public static void UseMvcPreConfigured(this WebApplication app) { - if (app == null) - throw new ArgumentNullException(nameof(app)); + ArgumentNullException.ThrowIfNull(app); - if (!env.IsDevelopment()) + if (!app.Environment.IsDevelopment()) { app.UseExceptionHandler("/Error/Unknown"); app.UseHsts(); } + app.UseCustomSerilog(); + app.UseHttpsRedirection(); app.UseStaticFiles(); app.UseRouting(); - app.UseMetrics(configuration); - app.UseAuthentication(); app.UseAuthorization(); diff --git a/src/1-BuildingBlocks/Web.MVC/Configuration/MVC/RazorPagesConfiguration.cs b/src/1-BuildingBlocks/Web.MVC/Configuration/MVC/RazorPagesConfiguration.cs index b95be5c16..8ed1b275e 100644 --- a/src/1-BuildingBlocks/Web.MVC/Configuration/MVC/RazorPagesConfiguration.cs +++ b/src/1-BuildingBlocks/Web.MVC/Configuration/MVC/RazorPagesConfiguration.cs @@ -1,9 +1,9 @@ using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Hosting; -using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Hosting; -using TaskoMask.BuildingBlocks.Web.MVC.Configuration.Metric; +using TaskoMask.BuildingBlocks.Web.MVC.Configuration.Observation.OpenTelemetry; +using TaskoMask.BuildingBlocks.Web.MVC.Configuration.Observation.Serilog; using TaskoMask.BuildingBlocks.Web.MVC.Services.AuthenticatedUser; namespace TaskoMask.BuildingBlocks.Web.MVC.Configuration.MVC; @@ -16,39 +16,39 @@ public static class RazorPagesConfiguration /// /// /// - public static void AddRazorPagesPreConfigured(this IServiceCollection services, IConfiguration configuration) + public static void AddRazorPagesPreConfigured(this WebApplicationBuilder builder) { - if (services == null) - throw new ArgumentNullException(nameof(services)); + ArgumentNullException.ThrowIfNull(builder); - services.AddRazorPages(); + builder.AddCustomSerilog(); - services.AddAuthentication(); + builder.Services.AddRazorPages(); - services.AddHttpContextAccessor(); + builder.Services.AddAuthentication(); - services.AddAuthenticatedUserService(); + builder.Services.AddHttpContextAccessor(); - services.AddMetrics(configuration); + builder.Services.AddAuthenticatedUserService(); + + builder.AddOpenTelemetry(); } /// /// /// - public static void UseRazorPagesPreConfigured(this IApplicationBuilder app, IWebHostEnvironment env, IConfiguration configuration) + public static void UseRazorPagesPreConfigured(this WebApplication app) { - if (app == null) - throw new ArgumentNullException(nameof(app)); + ArgumentNullException.ThrowIfNull(app); + + app.UseCustomSerilog(); - if (env.IsDevelopment()) + if (app.Environment.IsDevelopment()) app.UseDeveloperExceptionPage(); app.UseStaticFiles(); app.UseRouting(); - app.UseMetrics(configuration); - app.UseAuthorization(); } } diff --git a/src/1-BuildingBlocks/Web.MVC/Configuration/MVC/WebApiConfiguration.cs b/src/1-BuildingBlocks/Web.MVC/Configuration/MVC/WebApiConfiguration.cs index 270164118..fd1e6f2de 100644 --- a/src/1-BuildingBlocks/Web.MVC/Configuration/MVC/WebApiConfiguration.cs +++ b/src/1-BuildingBlocks/Web.MVC/Configuration/MVC/WebApiConfiguration.cs @@ -4,7 +4,8 @@ using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Hosting; using TaskoMask.BuildingBlocks.Web.MVC.Configuration.Jwt; -using TaskoMask.BuildingBlocks.Web.MVC.Configuration.Metric; +using TaskoMask.BuildingBlocks.Web.MVC.Configuration.Observation.OpenTelemetry; +using TaskoMask.BuildingBlocks.Web.MVC.Configuration.Observation.Serilog; using TaskoMask.BuildingBlocks.Web.MVC.Configuration.Swagger; using TaskoMask.BuildingBlocks.Web.MVC.Exceptions; using TaskoMask.BuildingBlocks.Web.MVC.Services.AuthenticatedUser; @@ -19,42 +20,46 @@ public static class WebApiConfiguration /// /// /// - public static void AddWebApiPreConfigured(this IServiceCollection services, IConfiguration configuration) + public static void AddWebApiPreConfigured(this WebApplicationBuilder builder) { - ArgumentNullException.ThrowIfNull(services); + ArgumentNullException.ThrowIfNull(builder); - services.AddControllers().WithPreventAutoValidation(); + builder.AddCustomSerilog(); - services.AddSwaggerPreConfigured(options => + builder.Services.AddControllers().WithPreventAutoValidation(); + + builder.Services.AddSwaggerPreConfigured(options => { - configuration.GetSection("Swagger").Bind(options); + builder.Configuration.GetSection("Swagger").Bind(options); }); - services.AddHttpContextAccessor(); + builder.Services.AddHttpContextAccessor(); - services.AddAuthenticatedUserService(); + builder.Services.AddAuthenticatedUserService(); - services.AddWebServerOptions(); + builder.Services.AddWebServerOptions(); - services.AddJwtAuthentication(configuration); + builder.Services.AddJwtAuthentication(builder.Configuration); - services.AddCors(); + builder.Services.AddCors(); - services.AddMetrics(configuration); + builder.AddOpenTelemetry(); - services.AddGlobalExceptionHandler(); + builder.Services.AddGlobalExceptionHandler(); } /// /// /// - public static void UseWebApiPreConfigured(this IApplicationBuilder app, IWebHostEnvironment env, IConfiguration configuration) + public static void UseWebApiPreConfigured(this WebApplication app) { ArgumentNullException.ThrowIfNull(app); - if (env.IsDevelopment()) + if (app.Environment.IsDevelopment()) app.UseDeveloperExceptionPage(); + app.UseCustomSerilog(); + app.UseGlobalExceptionHandler(); app.UseSwaggerPreConfigured(); @@ -65,8 +70,6 @@ public static void UseWebApiPreConfigured(this IApplicationBuilder app, IWebHost app.UseCors(builder => builder.AllowAnyOrigin().AllowAnyMethod().AllowAnyHeader()); - app.UseMetrics(configuration); - app.UseAuthentication(); app.UseAuthorization(); diff --git a/src/1-BuildingBlocks/Web.MVC/Web.MVC.csproj b/src/1-BuildingBlocks/Web.MVC/Web.MVC.csproj index a090c97b8..2d9b31c5a 100644 --- a/src/1-BuildingBlocks/Web.MVC/Web.MVC.csproj +++ b/src/1-BuildingBlocks/Web.MVC/Web.MVC.csproj @@ -22,8 +22,12 @@ - - + + + + + + diff --git a/src/2-Services/Boards/Api/Boards.Read.Api/Program.cs b/src/2-Services/Boards/Api/Boards.Read.Api/Program.cs index db3730493..2aaf49a7a 100644 --- a/src/2-Services/Boards/Api/Boards.Read.Api/Program.cs +++ b/src/2-Services/Boards/Api/Boards.Read.Api/Program.cs @@ -8,7 +8,7 @@ private static void Main(string[] args) { var builder = WebApplication.CreateBuilder(args); - var app = builder.ConfigureServices().ConfigurePipeline(builder.Configuration); + var app = builder.ConfigureServices().ConfigurePipeline(); app.Run(); } diff --git a/src/2-Services/Boards/Api/Boards.Read.Api/Startup.cs b/src/2-Services/Boards/Api/Boards.Read.Api/Startup.cs index 6cea2badd..1e97e6140 100644 --- a/src/2-Services/Boards/Api/Boards.Read.Api/Startup.cs +++ b/src/2-Services/Boards/Api/Boards.Read.Api/Startup.cs @@ -1,9 +1,7 @@ using Microsoft.AspNetCore.Builder; -using Microsoft.Extensions.Configuration; using Serilog; using TaskoMask.BuildingBlocks.Web.MVC.Configuration.Grpc; using TaskoMask.BuildingBlocks.Web.MVC.Configuration.MVC; -using TaskoMask.BuildingBlocks.Web.MVC.Configuration.Serilog; using TaskoMask.Services.Boards.Read.Api.Configuration; using TaskoMask.Services.Boards.Read.Api.Infrastructure.DbContext; using TaskoMask.Services.Boards.Read.Api.Infrastructure.DI; @@ -17,11 +15,9 @@ internal static class Startup /// public static WebApplication ConfigureServices(this WebApplicationBuilder builder) { - builder.AddCustomSerilog(); - builder.Services.AddModules(builder.Configuration); - builder.Services.AddWebApiPreConfigured(builder.Configuration); + builder.AddWebApiPreConfigured(); builder.Services.AddGrpcPreConfigured(); @@ -33,11 +29,11 @@ public static WebApplication ConfigureServices(this WebApplicationBuilder builde /// /// /// - public static WebApplication ConfigurePipeline(this WebApplication app, IConfiguration configuration) + public static WebApplication ConfigurePipeline(this WebApplication app) { app.UseSerilogRequestLogging(); - app.UseWebApiPreConfigured(app.Environment, configuration); + app.UseWebApiPreConfigured(); app.Services.InitialDatabase(); diff --git a/src/2-Services/Boards/Api/Boards.Read.Api/appsettings.json b/src/2-Services/Boards/Api/Boards.Read.Api/appsettings.json index 1bbc8aaee..d37b1607b 100644 --- a/src/2-Services/Boards/Api/Boards.Read.Api/appsettings.json +++ b/src/2-Services/Boards/Api/Boards.Read.Api/appsettings.json @@ -9,13 +9,14 @@ "UserName": "guest", "Password": "guest" }, - "Metric": { - "StandAloneKestrelServerEnabled": false, - "Port": 5025, - "Url": "/metrics", - "Hostname": "+", - "HttpMetricsEnabled": true, - "SuppressDefaultMetrics": false + "OpenTelemetry": { + "ServiceName": "TaskoMask", + "ExportMetrics": true, + "MetricsEndpoint": "http://localhost:4317", + "ExportTracing": true, + "TracingEndpoint": "http://localhost:4317", + "ExportLogging": false, + "LoggingEndpoint": "http://localhost:4317" }, "Caching": { "CacheTimeInMinutes": 60, diff --git a/src/2-Services/Boards/Api/Boards.Write.Api/Program.cs b/src/2-Services/Boards/Api/Boards.Write.Api/Program.cs index 9c81f62bb..71c103f3d 100644 --- a/src/2-Services/Boards/Api/Boards.Write.Api/Program.cs +++ b/src/2-Services/Boards/Api/Boards.Write.Api/Program.cs @@ -8,7 +8,7 @@ private static void Main(string[] args) { var builder = WebApplication.CreateBuilder(args); - var app = builder.ConfigureServices().ConfigurePipeline(builder.Configuration); + var app = builder.ConfigureServices().ConfigurePipeline(); app.Run(); } diff --git a/src/2-Services/Boards/Api/Boards.Write.Api/Startup.cs b/src/2-Services/Boards/Api/Boards.Write.Api/Startup.cs index 134811b3a..cfb07933e 100644 --- a/src/2-Services/Boards/Api/Boards.Write.Api/Startup.cs +++ b/src/2-Services/Boards/Api/Boards.Write.Api/Startup.cs @@ -1,8 +1,6 @@ using Microsoft.AspNetCore.Builder; -using Microsoft.Extensions.Configuration; using Serilog; using TaskoMask.BuildingBlocks.Web.MVC.Configuration.MVC; -using TaskoMask.BuildingBlocks.Web.MVC.Configuration.Serilog; using TaskoMask.Services.Boards.Write.Api.Infrastructure.CrossCutting.DI; using TaskoMask.Services.Boards.Write.Api.Infrastructure.Data.DbContext; @@ -15,11 +13,9 @@ internal static class Startup /// public static WebApplication ConfigureServices(this WebApplicationBuilder builder) { - builder.AddCustomSerilog(); - builder.Services.AddModules(builder.Configuration); - builder.Services.AddWebApiPreConfigured(builder.Configuration); + builder.AddWebApiPreConfigured(); return builder.Build(); } @@ -27,11 +23,11 @@ public static WebApplication ConfigureServices(this WebApplicationBuilder builde /// /// /// - public static WebApplication ConfigurePipeline(this WebApplication app, IConfiguration configuration) + public static WebApplication ConfigurePipeline(this WebApplication app) { app.UseSerilogRequestLogging(); - app.UseWebApiPreConfigured(app.Environment, configuration); + app.UseWebApiPreConfigured(); app.Services.InitialDatabasesAndSeedEssentialData(); diff --git a/src/2-Services/Boards/Api/Boards.Write.Api/appsettings.json b/src/2-Services/Boards/Api/Boards.Write.Api/appsettings.json index c4c2f8069..ff7975ae3 100644 --- a/src/2-Services/Boards/Api/Boards.Write.Api/appsettings.json +++ b/src/2-Services/Boards/Api/Boards.Write.Api/appsettings.json @@ -14,13 +14,14 @@ "Password": "Password", "KeyNamespace": "TaskoMaskEventStore" }, - "Metric": { - "StandAloneKestrelServerEnabled": false, - "Port": 5023, - "Url": "/metrics", - "Hostname": "+", - "HttpMetricsEnabled": true, - "SuppressDefaultMetrics": false + "OpenTelemetry": { + "ServiceName": "TaskoMask", + "ExportMetrics": true, + "MetricsEndpoint": "http://localhost:4317", + "ExportTracing": true, + "TracingEndpoint": "http://localhost:4317", + "ExportLogging": false, + "LoggingEndpoint": "http://localhost:4317" }, "Jwt": { "Authority": "https://identity.taskomask.ir", diff --git a/src/2-Services/Identity/Api/Identity.Api/Identity.Api.csproj b/src/2-Services/Identity/Api/Identity.Api/Identity.Api.csproj index a52314131..8c0d63cba 100644 --- a/src/2-Services/Identity/Api/Identity.Api/Identity.Api.csproj +++ b/src/2-Services/Identity/Api/Identity.Api/Identity.Api.csproj @@ -5,6 +5,7 @@ TaskoMask.Services.Identity.Api TaskoMask.Services.Identity.Api 755a7a1d-10e7-4626-9a60-81b74933b0b3 + NETSDK1206 Linux ..\..\..\..\.. ..\..\..\..\..\docker-compose.dcproj diff --git a/src/2-Services/Identity/Api/Identity.Api/Program.cs b/src/2-Services/Identity/Api/Identity.Api/Program.cs index 7b645ec7f..8e3e592c0 100644 --- a/src/2-Services/Identity/Api/Identity.Api/Program.cs +++ b/src/2-Services/Identity/Api/Identity.Api/Program.cs @@ -8,7 +8,7 @@ private static void Main(string[] args) { var builder = WebApplication.CreateBuilder(args); - var app = builder.ConfigureServices().ConfigurePipeline(builder.Configuration); + var app = builder.ConfigureServices().ConfigurePipeline(); app.Run(); } diff --git a/src/2-Services/Identity/Api/Identity.Api/Startup.cs b/src/2-Services/Identity/Api/Identity.Api/Startup.cs index 1f89935cf..10323330b 100644 --- a/src/2-Services/Identity/Api/Identity.Api/Startup.cs +++ b/src/2-Services/Identity/Api/Identity.Api/Startup.cs @@ -1,10 +1,8 @@ using Microsoft.AspNetCore.Builder; -using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using Serilog; using TaskoMask.BuildingBlocks.Web.MVC.Configuration.Captcha; using TaskoMask.BuildingBlocks.Web.MVC.Configuration.MVC; -using TaskoMask.BuildingBlocks.Web.MVC.Configuration.Serilog; using TaskoMask.Services.Identity.Api.Configuration; using TaskoMask.Services.Identity.Api.Infrastructure.CrossCutting.DI; @@ -17,9 +15,7 @@ internal static class Startup /// public static WebApplication ConfigureServices(this WebApplicationBuilder builder) { - builder.AddCustomSerilog(); - - builder.Services.AddRazorPagesPreConfigured(builder.Configuration); + builder.AddRazorPagesPreConfigured(); builder.Services.AddModules(builder.Configuration); @@ -35,13 +31,13 @@ public static WebApplication ConfigureServices(this WebApplicationBuilder builde /// /// /// - public static WebApplication ConfigurePipeline(this WebApplication app, IConfiguration configuration) + public static WebApplication ConfigurePipeline(this WebApplication app) { app.UseSerilogRequestLogging(); app.UseIdentityServer(); - app.UseRazorPagesPreConfigured(app.Environment, configuration); + app.UseRazorPagesPreConfigured(); app.Services.InitialDatabasesAndSeedEssentialData(); diff --git a/src/2-Services/Owners/Api/Owners.Read.Api/Program.cs b/src/2-Services/Owners/Api/Owners.Read.Api/Program.cs index a822c1891..6be6ecc8d 100644 --- a/src/2-Services/Owners/Api/Owners.Read.Api/Program.cs +++ b/src/2-Services/Owners/Api/Owners.Read.Api/Program.cs @@ -8,7 +8,7 @@ private static void Main(string[] args) { var builder = WebApplication.CreateBuilder(args); - var app = builder.ConfigureServices().ConfigurePipeline(builder.Configuration); + var app = builder.ConfigureServices().ConfigurePipeline(); app.Run(); } diff --git a/src/2-Services/Owners/Api/Owners.Read.Api/Startup.cs b/src/2-Services/Owners/Api/Owners.Read.Api/Startup.cs index 2ed952bd8..5d807350d 100644 --- a/src/2-Services/Owners/Api/Owners.Read.Api/Startup.cs +++ b/src/2-Services/Owners/Api/Owners.Read.Api/Startup.cs @@ -1,9 +1,7 @@ using Microsoft.AspNetCore.Builder; -using Microsoft.Extensions.Configuration; using Serilog; using TaskoMask.BuildingBlocks.Web.MVC.Configuration.Grpc; using TaskoMask.BuildingBlocks.Web.MVC.Configuration.MVC; -using TaskoMask.BuildingBlocks.Web.MVC.Configuration.Serilog; using TaskoMask.Services.Owners.Read.Api.Configuration; using TaskoMask.Services.Owners.Read.Api.Infrastructure.DbContext; using TaskoMask.Services.Owners.Read.Api.Infrastructure.DI; @@ -17,11 +15,9 @@ internal static class Startup /// public static WebApplication ConfigureServices(this WebApplicationBuilder builder) { - builder.AddCustomSerilog(); - builder.Services.AddModules(builder.Configuration); - builder.Services.AddWebApiPreConfigured(builder.Configuration); + builder.AddWebApiPreConfigured(); builder.Services.AddGrpcPreConfigured(); @@ -31,11 +27,11 @@ public static WebApplication ConfigureServices(this WebApplicationBuilder builde /// /// /// - public static WebApplication ConfigurePipeline(this WebApplication app, IConfiguration configuration) + public static WebApplication ConfigurePipeline(this WebApplication app) { app.UseSerilogRequestLogging(); - app.UseWebApiPreConfigured(app.Environment, configuration); + app.UseWebApiPreConfigured(); app.Services.InitialDatabase(); diff --git a/src/2-Services/Owners/Api/Owners.Write.Api/Program.cs b/src/2-Services/Owners/Api/Owners.Write.Api/Program.cs index b3348ceda..bc24a9a77 100644 --- a/src/2-Services/Owners/Api/Owners.Write.Api/Program.cs +++ b/src/2-Services/Owners/Api/Owners.Write.Api/Program.cs @@ -8,7 +8,7 @@ private static void Main(string[] args) { var builder = WebApplication.CreateBuilder(args); - var app = builder.ConfigureServices().ConfigurePipeline(builder.Configuration); + var app = builder.ConfigureServices().ConfigurePipeline(); app.Run(); } diff --git a/src/2-Services/Owners/Api/Owners.Write.Api/Startup.cs b/src/2-Services/Owners/Api/Owners.Write.Api/Startup.cs index 4e205baa6..320134992 100644 --- a/src/2-Services/Owners/Api/Owners.Write.Api/Startup.cs +++ b/src/2-Services/Owners/Api/Owners.Write.Api/Startup.cs @@ -1,8 +1,6 @@ using Microsoft.AspNetCore.Builder; -using Microsoft.Extensions.Configuration; using Serilog; using TaskoMask.BuildingBlocks.Web.MVC.Configuration.MVC; -using TaskoMask.BuildingBlocks.Web.MVC.Configuration.Serilog; using TaskoMask.Services.Owners.Write.Api.Infrastructure.CrossCutting.DI; using TaskoMask.Services.Owners.Write.Api.Infrastructure.Data.DbContext; @@ -15,11 +13,9 @@ internal static class Startup /// public static WebApplication ConfigureServices(this WebApplicationBuilder builder) { - builder.AddCustomSerilog(); - builder.Services.AddModules(builder.Configuration); - builder.Services.AddWebApiPreConfigured(builder.Configuration); + builder.AddWebApiPreConfigured(); return builder.Build(); } @@ -27,11 +23,11 @@ public static WebApplication ConfigureServices(this WebApplicationBuilder builde /// /// /// - public static WebApplication ConfigurePipeline(this WebApplication app, IConfiguration configuration) + public static WebApplication ConfigurePipeline(this WebApplication app) { app.UseSerilogRequestLogging(); - app.UseWebApiPreConfigured(app.Environment, configuration); + app.UseWebApiPreConfigured(); app.Services.InitialDatabasesAndSeedEssentialData(); diff --git a/src/2-Services/Tasks/Api/Tasks.Read.Api/Program.cs b/src/2-Services/Tasks/Api/Tasks.Read.Api/Program.cs index 343ea43f5..bfe1d5bf8 100644 --- a/src/2-Services/Tasks/Api/Tasks.Read.Api/Program.cs +++ b/src/2-Services/Tasks/Api/Tasks.Read.Api/Program.cs @@ -8,7 +8,7 @@ private static void Main(string[] args) { var builder = WebApplication.CreateBuilder(args); - var app = builder.ConfigureServices().ConfigurePipeline(builder.Configuration); + var app = builder.ConfigureServices().ConfigurePipeline(); app.Run(); } diff --git a/src/2-Services/Tasks/Api/Tasks.Read.Api/Startup.cs b/src/2-Services/Tasks/Api/Tasks.Read.Api/Startup.cs index 842cb364c..a145107b7 100644 --- a/src/2-Services/Tasks/Api/Tasks.Read.Api/Startup.cs +++ b/src/2-Services/Tasks/Api/Tasks.Read.Api/Startup.cs @@ -1,9 +1,7 @@ using Microsoft.AspNetCore.Builder; -using Microsoft.Extensions.Configuration; using Serilog; using TaskoMask.BuildingBlocks.Web.MVC.Configuration.Grpc; using TaskoMask.BuildingBlocks.Web.MVC.Configuration.MVC; -using TaskoMask.BuildingBlocks.Web.MVC.Configuration.Serilog; using TaskoMask.Services.Tasks.Read.Api.Configuration; using TaskoMask.Services.Tasks.Read.Api.Infrastructure.DbContext; using TaskoMask.Services.Tasks.Read.Api.Infrastructure.DI; @@ -17,11 +15,9 @@ internal static class Startup /// public static WebApplication ConfigureServices(this WebApplicationBuilder builder) { - builder.AddCustomSerilog(); - builder.Services.AddModules(builder.Configuration); - builder.Services.AddWebApiPreConfigured(builder.Configuration); + builder.AddWebApiPreConfigured(); builder.Services.AddGrpcPreConfigured(); @@ -33,11 +29,11 @@ public static WebApplication ConfigureServices(this WebApplicationBuilder builde /// /// /// - public static WebApplication ConfigurePipeline(this WebApplication app, IConfiguration configuration) + public static WebApplication ConfigurePipeline(this WebApplication app) { app.UseSerilogRequestLogging(); - app.UseWebApiPreConfigured(app.Environment, configuration); + app.UseWebApiPreConfigured(); app.Services.InitialDatabase(); diff --git a/src/2-Services/Tasks/Api/Tasks.Write.Api/Program.cs b/src/2-Services/Tasks/Api/Tasks.Write.Api/Program.cs index 1a1292f98..bb5795044 100644 --- a/src/2-Services/Tasks/Api/Tasks.Write.Api/Program.cs +++ b/src/2-Services/Tasks/Api/Tasks.Write.Api/Program.cs @@ -8,7 +8,7 @@ private static void Main(string[] args) { var builder = WebApplication.CreateBuilder(args); - var app = builder.ConfigureServices().ConfigurePipeline(builder.Configuration); + var app = builder.ConfigureServices().ConfigurePipeline(); app.Run(); } diff --git a/src/2-Services/Tasks/Api/Tasks.Write.Api/Startup.cs b/src/2-Services/Tasks/Api/Tasks.Write.Api/Startup.cs index 1b39dd2b7..d4830c03c 100644 --- a/src/2-Services/Tasks/Api/Tasks.Write.Api/Startup.cs +++ b/src/2-Services/Tasks/Api/Tasks.Write.Api/Startup.cs @@ -1,8 +1,6 @@ using Microsoft.AspNetCore.Builder; -using Microsoft.Extensions.Configuration; using Serilog; using TaskoMask.BuildingBlocks.Web.MVC.Configuration.MVC; -using TaskoMask.BuildingBlocks.Web.MVC.Configuration.Serilog; using TaskoMask.Services.Tasks.Write.Api.Infrastructure.CrossCutting.DI; using TaskoMask.Services.Tasks.Write.Api.Infrastructure.Data.DbContext; @@ -15,11 +13,9 @@ internal static class Startup /// public static WebApplication ConfigureServices(this WebApplicationBuilder builder) { - builder.AddCustomSerilog(); - builder.Services.AddModules(builder.Configuration); - builder.Services.AddWebApiPreConfigured(builder.Configuration); + builder.AddWebApiPreConfigured(); return builder.Build(); } @@ -27,11 +23,11 @@ public static WebApplication ConfigureServices(this WebApplicationBuilder builde /// /// /// - public static WebApplication ConfigurePipeline(this WebApplication app, IConfiguration configuration) + public static WebApplication ConfigurePipeline(this WebApplication app) { app.UseSerilogRequestLogging(); - app.UseWebApiPreConfigured(app.Environment, configuration); + app.UseWebApiPreConfigured(); app.Services.InitialDatabasesAndSeedEssentialData(); diff --git a/src/3-ApiGateways/UserPanel/Aggregator/Program.cs b/src/3-ApiGateways/UserPanel/Aggregator/Program.cs index 53cbe5ade..3c08fe209 100644 --- a/src/3-ApiGateways/UserPanel/Aggregator/Program.cs +++ b/src/3-ApiGateways/UserPanel/Aggregator/Program.cs @@ -6,7 +6,7 @@ private static void Main(string[] args) { var builder = WebApplication.CreateBuilder(args); - var app = builder.ConfigureServices().ConfigurePipeline(builder.Configuration); + var app = builder.ConfigureServices().ConfigurePipeline(); app.Run(); } diff --git a/src/3-ApiGateways/UserPanel/Aggregator/Startup.cs b/src/3-ApiGateways/UserPanel/Aggregator/Startup.cs index a9b27bf1f..302334898 100644 --- a/src/3-ApiGateways/UserPanel/Aggregator/Startup.cs +++ b/src/3-ApiGateways/UserPanel/Aggregator/Startup.cs @@ -2,7 +2,6 @@ using TaskoMask.ApiGateways.UserPanel.Aggregator.Configuration; using TaskoMask.ApiGateways.UserPanel.Aggregator.Infrastructure.DI; using TaskoMask.BuildingBlocks.Web.MVC.Configuration.MVC; -using TaskoMask.BuildingBlocks.Web.MVC.Configuration.Serilog; namespace TaskoMask.ApiGateways.UserPanel.Aggregator; @@ -13,11 +12,9 @@ internal static class Startup /// public static WebApplication ConfigureServices(this WebApplicationBuilder builder) { - builder.AddCustomSerilog(); - builder.Services.AddModules(builder.Configuration); - builder.Services.AddWebApiPreConfigured(builder.Configuration); + builder.AddWebApiPreConfigured(); builder.Services.AddGrpcClients(builder.Configuration); @@ -27,11 +24,11 @@ public static WebApplication ConfigureServices(this WebApplicationBuilder builde /// /// /// - public static WebApplication ConfigurePipeline(this WebApplication app, IConfiguration configuration) + public static WebApplication ConfigurePipeline(this WebApplication app) { app.UseSerilogRequestLogging(); - app.UseWebApiPreConfigured(app.Environment, configuration); + app.UseWebApiPreConfigured(); app.MapControllers(); diff --git a/src/3-ApiGateways/UserPanel/ApiGateway/Program.cs b/src/3-ApiGateways/UserPanel/ApiGateway/Program.cs index dd5a1e114..bcaa83027 100644 --- a/src/3-ApiGateways/UserPanel/ApiGateway/Program.cs +++ b/src/3-ApiGateways/UserPanel/ApiGateway/Program.cs @@ -6,7 +6,7 @@ private static void Main(string[] args) { var builder = WebApplication.CreateBuilder(args); - var app = builder.ConfigureServices().ConfigurePipeline(builder.Configuration); + var app = builder.ConfigureServices().ConfigurePipeline(); app.Run(); } diff --git a/src/3-ApiGateways/UserPanel/ApiGateway/Startup.cs b/src/3-ApiGateways/UserPanel/ApiGateway/Startup.cs index 966bc1add..e6657b0ff 100644 --- a/src/3-ApiGateways/UserPanel/ApiGateway/Startup.cs +++ b/src/3-ApiGateways/UserPanel/ApiGateway/Startup.cs @@ -3,8 +3,6 @@ using Ocelot.Middleware; using Serilog; using TaskoMask.BuildingBlocks.Web.MVC.Configuration.Captcha; -using TaskoMask.BuildingBlocks.Web.MVC.Configuration.Metric; -using TaskoMask.BuildingBlocks.Web.MVC.Configuration.Serilog; namespace TaskoMask.ApiGateways.UserPanel.ApiGateway; @@ -15,8 +13,6 @@ internal static class Startup /// public static WebApplication ConfigureServices(this WebApplicationBuilder builder) { - builder.AddCustomSerilog(); - //TODO : Swagger tries to initialize DNTCaptcha.Core built-in controller and throws an error if we remove the bellow lines // We need to ignore DNTCaptcha.Core during generating swagger docs builder.Services.AddControllers(); @@ -37,8 +33,6 @@ public static WebApplication ConfigureServices(this WebApplicationBuilder builde builder.Services.AddCors(); - builder.Services.AddMetrics(builder.Configuration); - builder .Services.AddAuthentication() .AddJwtBearer( @@ -56,7 +50,7 @@ public static WebApplication ConfigureServices(this WebApplicationBuilder builde /// /// /// - public static WebApplication ConfigurePipeline(this WebApplication app, IConfiguration configuration) + public static WebApplication ConfigurePipeline(this WebApplication app) { app.UseSerilogRequestLogging(); @@ -69,8 +63,6 @@ public static WebApplication ConfigurePipeline(this WebApplication app, IConfigu app.UseCors(builder => builder.AllowAnyOrigin().AllowAnyMethod().AllowAnyHeader()); - app.UseMetrics(configuration); - app.UseOcelot().Wait(); return app; diff --git a/src/4-Clients/UserPanel/Startup.cs b/src/4-Clients/UserPanel/Startup.cs index 3de849b32..33b16dd7c 100644 --- a/src/4-Clients/UserPanel/Startup.cs +++ b/src/4-Clients/UserPanel/Startup.cs @@ -19,8 +19,7 @@ public static class Startup /// public static void ConfigureServices(this IServiceCollection services, IConfiguration configuration) { - if (services == null) - throw new ArgumentNullException(nameof(services)); + ArgumentNullException.ThrowIfNull(services); services.AddHttpServices(configuration); services.AddApiServices(); diff --git a/src/4-Clients/Website/Program.cs b/src/4-Clients/Website/Program.cs index 9acbf3918..568a5ad2a 100644 --- a/src/4-Clients/Website/Program.cs +++ b/src/4-Clients/Website/Program.cs @@ -6,7 +6,7 @@ private static void Main(string[] args) { var builder = WebApplication.CreateBuilder(args); - var app = builder.ConfigureServices().ConfigurePipeline(builder.Configuration); + var app = builder.ConfigureServices().ConfigurePipeline(); app.Run(); } diff --git a/src/4-Clients/Website/Startup.cs b/src/4-Clients/Website/Startup.cs index 5e2e86f2a..7364090d1 100644 --- a/src/4-Clients/Website/Startup.cs +++ b/src/4-Clients/Website/Startup.cs @@ -1,6 +1,5 @@ using Serilog; using TaskoMask.BuildingBlocks.Web.MVC.Configuration.MVC; -using TaskoMask.BuildingBlocks.Web.MVC.Configuration.Serilog; namespace TaskoMask.Clients.Website; @@ -11,9 +10,7 @@ internal static class Startup /// public static WebApplication ConfigureServices(this WebApplicationBuilder builder) { - builder.AddCustomSerilog(); - - builder.Services.AddMvcPreConfigured(builder.Configuration); + builder.AddMvcPreConfigured(); return builder.Build(); } @@ -21,11 +18,11 @@ public static WebApplication ConfigureServices(this WebApplicationBuilder builde /// /// /// - public static WebApplication ConfigurePipeline(this WebApplication app, IConfiguration configuration) + public static WebApplication ConfigurePipeline(this WebApplication app) { app.UseSerilogRequestLogging(); - app.UseMvcPreConfigured(app.Environment, configuration); + app.UseMvcPreConfigured(); app.MapControllerRoute(name: "default", pattern: "{controller=Home}/{action=Index}/{id?}");