All checks were successful
Caddy Manager CI build / docker (push) Successful in 1m16s
26 lines
945 B
C#
26 lines
945 B
C#
using NetCore.AutoRegisterDi;
|
|
using Microsoft.Extensions.Configuration;
|
|
using CaddyManager.Contracts.Configurations.Caddy;
|
|
using CaddyManager.Contracts.Configurations.Docker;
|
|
using CaddyManager.Contracts.Configurations;
|
|
|
|
namespace CaddyManager.Services.Configurations;
|
|
|
|
/// <inheritdoc />
|
|
[RegisterAsSingleton]
|
|
public class ConfigurationsService(IConfiguration configuration) : IConfigurationsService
|
|
{
|
|
/// <inheritdoc />
|
|
public T Get<T>() where T : class
|
|
{
|
|
var section = typeof(T).Name;
|
|
|
|
// Have the configuration section name be the section name without the "Configurations" suffix
|
|
if (section.EndsWith("Configurations"))
|
|
section = section[..^"Configurations".Length];
|
|
else if (section.EndsWith("Configuration"))
|
|
section = section[..^"Configuration".Length];
|
|
|
|
return configuration.GetSection(section).Get<T>() ?? Activator.CreateInstance<T>();
|
|
}
|
|
} |