refactor(EnvelopeSmsService): Initialisiert mit Schnittstelle, DI-Injektion und Konfigurationen.

This commit is contained in:
Developer 02
2025-01-31 11:15:53 +01:00
parent 22347a0202
commit 1941de1928
4 changed files with 29 additions and 3 deletions

View File

@@ -0,0 +1,33 @@
using System.Globalization;
namespace EnvelopeGenerator.Application.Configurations
{
public class TotpSmsParams
{
/// <summary>
/// The unit is second.
/// </summary>
public int TotpStep { get; init; } = 90;
public string Format { get; init; } = "Ihr 2FA-Passwort lautet {0}. Gültig bis {1}";
public ExpirationHandler Expiration { get; init; } = new();
public class ExpirationHandler
{
public string CacheKeyFormat { get; init; } = "e{0}_r{1}_sms_code_expiration";
public string Format { get; init; } = "HH:mm:ss";
public string CultureName
{
get => _cultureInfo.Name;
init => _cultureInfo = new(value);
}
private CultureInfo _cultureInfo = new("de-DE");
public CultureInfo CultureInfo => _cultureInfo;
}
}
}

View File

@@ -0,0 +1,5 @@
namespace EnvelopeGenerator.Application.Contracts;
public interface IEnvelopeSmsService
{
}

View File

@@ -16,7 +16,7 @@ namespace EnvelopeGenerator.Application.Extensions
{
public static class DIExtensions
{
public static IServiceCollection AddEnvelopeGenerator(this IServiceCollection services, IConfigurationSection dispatcherConfigSection, IConfigurationSection mailConfigSection, IConfigurationSection smsConfigSection, IConfigurationSection codeGeneratorConfigSection, IConfigurationSection envelopeReceiverCacheParamsSection)
public static IServiceCollection AddEnvelopeGenerator(this IServiceCollection services, IConfigurationSection dispatcherConfigSection, IConfigurationSection mailConfigSection, IConfigurationSection smsConfigSection, IConfigurationSection codeGeneratorConfigSection, IConfigurationSection envelopeReceiverCacheParamsSection, IConfigurationSection totpSmsParamsSection)
{
//Inject CRUD Service and repositoriesad
services.TryAddScoped<IConfigRepository, ConfigRepository>();
@@ -58,9 +58,11 @@ namespace EnvelopeGenerator.Application.Extensions
services.Configure<MailConfig>(mailConfigSection);
services.Configure<CodeGeneratorParams>(codeGeneratorConfigSection);
services.Configure<EnvelopeReceiverCacheParams>(envelopeReceiverCacheParamsSection);
services.Configure<TotpSmsParams>(totpSmsParamsSection);
services.AddHttpClientService<SmsParams>(smsConfigSection);
services.TryAddSingleton<ISmsSender, GTXSmsSender>();
services.TryAddSingleton<IEnvelopeSmsService, EnvelopeSmsService>();
services.TryAddSingleton<ICodeGenerator, CodeGenerator>();
services.TryAddSingleton<QRCodeGenerator>();
@@ -72,6 +74,7 @@ namespace EnvelopeGenerator.Application.Extensions
mailConfigSection: config.GetSection("MailConfig"),
smsConfigSection: config.GetSection("SmsConfig"),
codeGeneratorConfigSection: config.GetSection("CodeGeneratorParams"),
envelopeReceiverCacheParamsSection: config.GetSection("EnvelopeReceiverCacheParams"));
envelopeReceiverCacheParamsSection: config.GetSection("EnvelopeReceiverCacheParams"),
totpSmsParamsSection: config.GetSection("TotpSmsParams"));
}
}

View File

@@ -0,0 +1,18 @@
using EnvelopeGenerator.Application.Configurations;
using EnvelopeGenerator.Application.Contracts;
using Microsoft.Extensions.Options;
namespace EnvelopeGenerator.Application.Services;
public class EnvelopeSmsService : IEnvelopeSmsService
{
private readonly ISmsSender _sender;
private readonly TotpSmsParams _totpSmsParams;
public EnvelopeSmsService(ISmsSender sender, IOptions<TotpSmsParams> totpSmsParamsOptions)
{
_sender = sender;
_totpSmsParams = totpSmsParamsOptions.Value;
}
}