fix: get GeneralConfig
This commit is contained in:
parent
8e58c83526
commit
6797adac4f
@ -1,5 +1,6 @@
|
|||||||
using Microsoft.Extensions.Configuration;
|
using Microsoft.Extensions.Configuration;
|
||||||
using Microsoft.Extensions.DependencyInjection;
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
|
using Mirea.Api.Endpoint.Configuration.General;
|
||||||
using Mirea.Api.Endpoint.Configuration.General.Settings;
|
using Mirea.Api.Endpoint.Configuration.General.Settings;
|
||||||
|
|
||||||
namespace Mirea.Api.Endpoint.Configuration.AppConfig;
|
namespace Mirea.Api.Endpoint.Configuration.AppConfig;
|
||||||
@ -8,7 +9,7 @@ public static class CacheConfiguration
|
|||||||
{
|
{
|
||||||
public static IServiceCollection AddCustomRedis(this IServiceCollection services, IConfiguration configuration)
|
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)
|
if (cache?.TypeDatabase == CacheSettings.CacheEnum.Redis)
|
||||||
{
|
{
|
||||||
services.AddStackExchangeRedisCache(options =>
|
services.AddStackExchangeRedisCache(options =>
|
||||||
|
@ -17,7 +17,7 @@ public static class LoggerConfiguration
|
|||||||
{
|
{
|
||||||
hostBuilder.UseSerilog((context, _, configuration) =>
|
hostBuilder.UseSerilog((context, _, configuration) =>
|
||||||
{
|
{
|
||||||
var generalConfig = context.Configuration.Get<GeneralConfig>();
|
var generalConfig = context.Configuration.Get<GeneralConfig>()?.LogSettings;
|
||||||
configuration
|
configuration
|
||||||
.MinimumLevel.Debug()
|
.MinimumLevel.Debug()
|
||||||
.MinimumLevel.Override("Microsoft", LogEventLevel.Information)
|
.MinimumLevel.Override("Microsoft", LogEventLevel.Information)
|
||||||
@ -26,16 +26,16 @@ public static class LoggerConfiguration
|
|||||||
outputTemplate:
|
outputTemplate:
|
||||||
"[{Level:u3}] [{Timestamp:dd.MM.yyyy HH:mm:ss}] {Message:lj}{NewLine}{Exception}");
|
"[{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)))
|
if (!string.IsNullOrEmpty(generalConfig.LogFilePath) && Directory.Exists(PathBuilder.Combine(generalConfig.LogFilePath)))
|
||||||
Directory.CreateDirectory(generalConfig.LogSettings.LogFilePath);
|
Directory.CreateDirectory(generalConfig.LogFilePath);
|
||||||
|
|
||||||
configuration.WriteTo.File(
|
configuration.WriteTo.File(
|
||||||
new CompactJsonFormatter(),
|
new CompactJsonFormatter(),
|
||||||
PathBuilder.Combine(
|
PathBuilder.Combine(
|
||||||
generalConfig.LogSettings.LogFilePath!,
|
generalConfig.LogFilePath!,
|
||||||
generalConfig.LogSettings.LogFileName + ".json"
|
generalConfig.LogFileName + ".json"
|
||||||
),
|
),
|
||||||
LogEventLevel.Debug,
|
LogEventLevel.Debug,
|
||||||
rollingInterval: RollingInterval.Day);
|
rollingInterval: RollingInterval.Day);
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
using Microsoft.Extensions.Configuration;
|
using Microsoft.Extensions.Configuration;
|
||||||
using Microsoft.Extensions.DependencyInjection;
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
using Mirea.Api.Endpoint.Common.Services.Security;
|
using Mirea.Api.Endpoint.Common.Services.Security;
|
||||||
|
using Mirea.Api.Endpoint.Configuration.General;
|
||||||
using Mirea.Api.Endpoint.Configuration.General.Settings;
|
using Mirea.Api.Endpoint.Configuration.General.Settings;
|
||||||
using Mirea.Api.Security;
|
using Mirea.Api.Security;
|
||||||
using Mirea.Api.Security.Common.Interfaces;
|
using Mirea.Api.Security.Common.Interfaces;
|
||||||
@ -16,7 +17,7 @@ public static class SecureConfiguration
|
|||||||
services.AddSingleton<IAccessToken, JwtTokenService>();
|
services.AddSingleton<IAccessToken, JwtTokenService>();
|
||||||
services.AddSingleton<IRevokedToken, MemoryRevokedTokenService>();
|
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>();
|
services.AddSingleton<ICacheService, DistributedCacheService>();
|
||||||
else
|
else
|
||||||
services.AddSingleton<ICacheService, MemoryCacheService>();
|
services.AddSingleton<ICacheService, MemoryCacheService>();
|
||||||
|
@ -9,7 +9,6 @@ using Mirea.Api.Endpoint.Common.Interfaces;
|
|||||||
using Mirea.Api.Endpoint.Common.Services;
|
using Mirea.Api.Endpoint.Common.Services;
|
||||||
using Mirea.Api.Endpoint.Configuration.AppConfig;
|
using Mirea.Api.Endpoint.Configuration.AppConfig;
|
||||||
using Mirea.Api.Endpoint.Configuration.General;
|
using Mirea.Api.Endpoint.Configuration.General;
|
||||||
using Mirea.Api.Endpoint.Configuration.General.Settings;
|
|
||||||
using Mirea.Api.Endpoint.Configuration.General.Validators;
|
using Mirea.Api.Endpoint.Configuration.General.Validators;
|
||||||
using Mirea.Api.Endpoint.Middleware;
|
using Mirea.Api.Endpoint.Middleware;
|
||||||
using System;
|
using System;
|
||||||
@ -21,7 +20,7 @@ public class Program
|
|||||||
{
|
{
|
||||||
public static IServiceCollection AddDatabase(IServiceCollection services, IConfiguration configuration)
|
public static IServiceCollection AddDatabase(IServiceCollection services, IConfiguration configuration)
|
||||||
{
|
{
|
||||||
var dbSettings = configuration.Get<DbSettings>();
|
var dbSettings = configuration.Get<GeneralConfig>()?.DbSettings;
|
||||||
services.AddApplication();
|
services.AddApplication();
|
||||||
services.AddPersistence(
|
services.AddPersistence(
|
||||||
dbSettings?.DatabaseProvider ?? DatabaseProvider.Sqlite,
|
dbSettings?.DatabaseProvider ?? DatabaseProvider.Sqlite,
|
||||||
|
Loading…
Reference in New Issue
Block a user