Add Application configuration #11

Merged
Wesser merged 128 commits from feat/add-setup into release/v1.0.0 2024-06-01 07:35:30 +03:00
Showing only changes of commit 08f13108d8 - Show all commits

View File

@ -0,0 +1,38 @@
using Microsoft.Extensions.Options;
using Mirea.Api.Endpoint.Configuration.General.Attributes;
using Mirea.Api.Endpoint.Configuration.General.Interfaces;
using System;
using System.Reflection;
namespace Mirea.Api.Endpoint.Configuration.General.Validators;
public class SettingsRequiredValidator
{
private readonly GeneralConfig _generalConfig;
public SettingsRequiredValidator(IOptionsSnapshot<GeneralConfig> configuration) =>
_generalConfig = configuration.Value;
public SettingsRequiredValidator(GeneralConfig configuration) =>
_generalConfig = configuration;
public bool AreSettingsValid()
{
foreach (var property in _generalConfig
.GetType()
.GetProperties(BindingFlags.Public | BindingFlags.Instance))
{
if (!Attribute.IsDefined(property.PropertyType, typeof(RequiredSettingsAttribute))) continue;
var value = property.GetValue(_generalConfig);
if (value == null)
return false;
var isConfigured = value as IIsConfigured;
if (!isConfigured!.IsConfigured())
return false;
}
return true;
}
}