From 35eb1eab39791838ca3fa75ceb2f622ea8bde06c Mon Sep 17 00:00:00 2001 From: Polianin Nikita Date: Tue, 28 May 2024 07:12:58 +0300 Subject: [PATCH] feat: implement validation of settings --- Endpoint/Program.cs | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/Endpoint/Program.cs b/Endpoint/Program.cs index 340478c..0938434 100644 --- a/Endpoint/Program.cs +++ b/Endpoint/Program.cs @@ -12,6 +12,7 @@ using Mirea.Api.Endpoint.Common.Interfaces; using Mirea.Api.Endpoint.Common.Services; using Mirea.Api.Endpoint.Configuration; using Mirea.Api.Endpoint.Configuration.General; +using Mirea.Api.Endpoint.Configuration.General.Validators; using Mirea.Api.Endpoint.Configuration.Swagger; using Mirea.Api.Endpoint.Middleware; using Swashbuckle.AspNetCore.SwaggerGen; @@ -100,8 +101,25 @@ public class Program Console.WriteLine($"{item.Key}:{item.Value}"); #endif - var uber = app.Services.CreateScope().ServiceProvider.GetService(); - DbInitializer.Initialize(uber!); + using (var scope = app.Services.CreateScope()) + { + var serviceProvider = scope.ServiceProvider; + + var optionsSnapshot = serviceProvider.GetRequiredService>(); + var settingsValidator = new SettingsRequiredValidator(optionsSnapshot); + var isDoneConfig = settingsValidator.AreSettingsValid(); + + if (isDoneConfig) + { + var uberDbContext = serviceProvider.GetRequiredService(); + var maintenanceModeService = serviceProvider.GetRequiredService(); + + maintenanceModeService.DisableMaintenanceMode(); + DbInitializer.Initialize(uberDbContext); + + // todo: if admin not found + } + } // Configure the HTTP request pipeline. if (app.Environment.IsDevelopment())