SocialPub/PrivaPub/Services/AppConfigurationService.cs

37 lines
996 B
C#
Raw Normal View History

2023-02-18 08:52:17 +01:00
using Microsoft.Extensions.Options;
using MongoDB.Entities;
2023-02-19 00:43:43 +01:00
using PrivaPub.Models;
using PrivaPub.StaticServices;
2023-02-18 08:52:17 +01:00
2023-02-19 00:43:43 +01:00
namespace PrivaPub.Services
2023-02-18 08:52:17 +01:00
{
public class AppConfigurationService
{
public AppConfiguration AppConfiguration;
readonly DbEntities _dbEntities;
AppConfiguration _appConfigurationFromFile;
public AppConfigurationService(DbEntities dbEntities, IOptionsMonitor<AppConfiguration> appConfiguration)
{
_dbEntities = dbEntities;
_appConfigurationFromFile = appConfiguration.CurrentValue;
}
public async Task Init()
{
var dbAppConfiguration = await _dbEntities.AppConfiguration.ExecuteFirstAsync();
if (dbAppConfiguration != default)
{
if (AppConfiguration == default || AppConfiguration.LastUpdateDate != dbAppConfiguration.LastUpdateDate)
AppConfiguration = dbAppConfiguration;
return;
}
dbAppConfiguration = _appConfigurationFromFile;
await dbAppConfiguration.SaveAsync();
AppConfiguration = dbAppConfiguration;
}
}
}