fix: get GeneralConfig
This commit is contained in:
parent
8e58c83526
commit
6797adac4f
@ -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<CacheSettings>();
|
||||
var cache = configuration.Get<GeneralConfig>()?.CacheSettings;
|
||||
if (cache?.TypeDatabase == CacheSettings.CacheEnum.Redis)
|
||||
{
|
||||
services.AddStackExchangeRedisCache(options =>
|
||||
|
@ -17,7 +17,7 @@ public static class LoggerConfiguration
|
||||
{
|
||||
hostBuilder.UseSerilog((context, _, configuration) =>
|
||||
{
|
||||
var generalConfig = context.Configuration.Get<GeneralConfig>();
|
||||
var generalConfig = context.Configuration.Get<GeneralConfig>()?.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);
|
||||
|
@ -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<IAccessToken, JwtTokenService>();
|
||||
services.AddSingleton<IRevokedToken, MemoryRevokedTokenService>();
|
||||
|
||||
if (configuration.Get<CacheSettings>()?.TypeDatabase == CacheSettings.CacheEnum.Redis)
|
||||
if (configuration.Get<GeneralConfig>()?.CacheSettings?.TypeDatabase == CacheSettings.CacheEnum.Redis)
|
||||
services.AddSingleton<ICacheService, DistributedCacheService>();
|
||||
else
|
||||
services.AddSingleton<ICacheService, MemoryCacheService>();
|
||||
|
@ -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<DbSettings>();
|
||||
var dbSettings = configuration.Get<GeneralConfig>()?.DbSettings;
|
||||
services.AddApplication();
|
||||
services.AddPersistence(
|
||||
dbSettings?.DatabaseProvider ?? DatabaseProvider.Sqlite,
|
||||
|
Loading…
Reference in New Issue
Block a user