Compare commits

...

2 Commits

Author SHA1 Message Date
993e66a084 fix: add JsonIgnore to calculated property
All checks were successful
.NET Test Pipeline / build-and-test (push) Successful in 3m46s
2024-06-01 11:11:21 +03:00
6797adac4f fix: get GeneralConfig 2024-06-01 11:10:42 +03:00
5 changed files with 13 additions and 10 deletions

View File

@ -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 =>

View File

@ -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);

View File

@ -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>();

View File

@ -2,6 +2,7 @@
using Mirea.Api.Endpoint.Configuration.General.Attributes; using Mirea.Api.Endpoint.Configuration.General.Attributes;
using Mirea.Api.Endpoint.Configuration.General.Interfaces; using Mirea.Api.Endpoint.Configuration.General.Interfaces;
using System; using System;
using System.Text.Json.Serialization;
namespace Mirea.Api.Endpoint.Configuration.General.Settings; namespace Mirea.Api.Endpoint.Configuration.General.Settings;
@ -17,6 +18,7 @@ public class DbSettings : IIsConfigured
public DatabaseEnum TypeDatabase { get; set; } public DatabaseEnum TypeDatabase { get; set; }
public required string ConnectionStringSql { get; set; } public required string ConnectionStringSql { get; set; }
[JsonIgnore]
public DatabaseProvider DatabaseProvider => public DatabaseProvider DatabaseProvider =>
TypeDatabase switch TypeDatabase switch
{ {

View File

@ -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,