From 6797adac4fec69fc50c420d10d8328c74d4349ea Mon Sep 17 00:00:00 2001 From: Polianin Nikita Date: Sat, 1 Jun 2024 11:10:42 +0300 Subject: [PATCH] fix: get GeneralConfig --- .../Configuration/AppConfig/CacheConfiguration.cs | 3 ++- .../Configuration/AppConfig/LoggerConfiguration.cs | 12 ++++++------ .../Configuration/AppConfig/SecureConfiguration.cs | 3 ++- Endpoint/Program.cs | 3 +-- 4 files changed, 11 insertions(+), 10 deletions(-) diff --git a/Endpoint/Configuration/AppConfig/CacheConfiguration.cs b/Endpoint/Configuration/AppConfig/CacheConfiguration.cs index 7a1954c..bab6483 100644 --- a/Endpoint/Configuration/AppConfig/CacheConfiguration.cs +++ b/Endpoint/Configuration/AppConfig/CacheConfiguration.cs @@ -1,5 +1,6 @@ using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; +using Mirea.Api.Endpoint.Configuration.General; using Mirea.Api.Endpoint.Configuration.General.Settings; namespace Mirea.Api.Endpoint.Configuration.AppConfig; @@ -8,7 +9,7 @@ public static class CacheConfiguration { public static IServiceCollection AddCustomRedis(this IServiceCollection services, IConfiguration configuration) { - var cache = configuration.Get(); + var cache = configuration.Get()?.CacheSettings; if (cache?.TypeDatabase == CacheSettings.CacheEnum.Redis) { services.AddStackExchangeRedisCache(options => diff --git a/Endpoint/Configuration/AppConfig/LoggerConfiguration.cs b/Endpoint/Configuration/AppConfig/LoggerConfiguration.cs index d10e5a4..06e9f53 100644 --- a/Endpoint/Configuration/AppConfig/LoggerConfiguration.cs +++ b/Endpoint/Configuration/AppConfig/LoggerConfiguration.cs @@ -17,7 +17,7 @@ public static class LoggerConfiguration { hostBuilder.UseSerilog((context, _, configuration) => { - var generalConfig = context.Configuration.Get(); + var generalConfig = context.Configuration.Get()?.LogSettings; configuration .MinimumLevel.Debug() .MinimumLevel.Override("Microsoft", LogEventLevel.Information) @@ -26,16 +26,16 @@ public static class LoggerConfiguration outputTemplate: "[{Level:u3}] [{Timestamp:dd.MM.yyyy HH:mm:ss}] {Message:lj}{NewLine}{Exception}"); - if (generalConfig?.LogSettings?.EnableLogToFile == true) + if (generalConfig?.EnableLogToFile == true) { - if (!string.IsNullOrEmpty(generalConfig.LogSettings.LogFilePath) && Directory.Exists(PathBuilder.Combine(generalConfig.LogSettings.LogFilePath))) - Directory.CreateDirectory(generalConfig.LogSettings.LogFilePath); + if (!string.IsNullOrEmpty(generalConfig.LogFilePath) && Directory.Exists(PathBuilder.Combine(generalConfig.LogFilePath))) + Directory.CreateDirectory(generalConfig.LogFilePath); configuration.WriteTo.File( new CompactJsonFormatter(), PathBuilder.Combine( - generalConfig.LogSettings.LogFilePath!, - generalConfig.LogSettings.LogFileName + ".json" + generalConfig.LogFilePath!, + generalConfig.LogFileName + ".json" ), LogEventLevel.Debug, rollingInterval: RollingInterval.Day); diff --git a/Endpoint/Configuration/AppConfig/SecureConfiguration.cs b/Endpoint/Configuration/AppConfig/SecureConfiguration.cs index fb8cd00..fd84f06 100644 --- a/Endpoint/Configuration/AppConfig/SecureConfiguration.cs +++ b/Endpoint/Configuration/AppConfig/SecureConfiguration.cs @@ -1,6 +1,7 @@ using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using Mirea.Api.Endpoint.Common.Services.Security; +using Mirea.Api.Endpoint.Configuration.General; using Mirea.Api.Endpoint.Configuration.General.Settings; using Mirea.Api.Security; using Mirea.Api.Security.Common.Interfaces; @@ -16,7 +17,7 @@ public static class SecureConfiguration services.AddSingleton(); services.AddSingleton(); - if (configuration.Get()?.TypeDatabase == CacheSettings.CacheEnum.Redis) + if (configuration.Get()?.CacheSettings?.TypeDatabase == CacheSettings.CacheEnum.Redis) services.AddSingleton(); else services.AddSingleton(); diff --git a/Endpoint/Program.cs b/Endpoint/Program.cs index 4dab4df..2a9da94 100644 --- a/Endpoint/Program.cs +++ b/Endpoint/Program.cs @@ -9,7 +9,6 @@ using Mirea.Api.Endpoint.Common.Interfaces; using Mirea.Api.Endpoint.Common.Services; using Mirea.Api.Endpoint.Configuration.AppConfig; using Mirea.Api.Endpoint.Configuration.General; -using Mirea.Api.Endpoint.Configuration.General.Settings; using Mirea.Api.Endpoint.Configuration.General.Validators; using Mirea.Api.Endpoint.Middleware; using System; @@ -21,7 +20,7 @@ public class Program { public static IServiceCollection AddDatabase(IServiceCollection services, IConfiguration configuration) { - var dbSettings = configuration.Get(); + var dbSettings = configuration.Get()?.DbSettings; services.AddApplication(); services.AddPersistence( dbSettings?.DatabaseProvider ?? DatabaseProvider.Sqlite,