refaktor: Vereinfachung der DI-Konfiguration und Verbesserung der Wiederverwendbarkeit
- Entfernte redundante `AddEnvelopeGenerator`-Überladung. - Einführung der Erweiterungsmethode `ConfigureByTypeName<TOptions>` für eine sauberere Konfiguration. - Ersetzte explizite Konfigurationsaufrufe durch `ConfigureByTypeName<TOptions>`. - Verbesserte Wartbarkeit durch Reduzierung von redundantem Code. - Markierte `ConfigureByTypeName<TOptions>` zur zukünftigen Verlagerung nach `DigitalData.Core`.
This commit is contained in:
parent
eb0c6dabf4
commit
363329ca18
@ -1,17 +0,0 @@
|
||||
namespace EnvelopeGenerator.Application.Configurations
|
||||
{
|
||||
public class EnvelopeReceiverCacheParams
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets the cache key format for SMS codes.
|
||||
/// The placeholder {0} represents the envelopeReceiverId.
|
||||
/// </summary>
|
||||
public string CodeCacheKeyFormat { get; init; } = "sms-code-{0}";
|
||||
|
||||
/// <summary>
|
||||
/// Gets the cache expiration key format for SMS codes.
|
||||
/// The placeholder {0} represents the envelopeReceiverId.
|
||||
/// </summary>
|
||||
public string CodeExpirationCacheKeyFormat { get; init; } = "sms-code-expiration-{0}";
|
||||
}
|
||||
}
|
||||
@ -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, IConfigurationSection totpSmsParamsSection)
|
||||
public static IServiceCollection AddEnvelopeGenerator(this IServiceCollection services, IConfiguration config)
|
||||
{
|
||||
//Inject CRUD Service and repositoriesad
|
||||
services.TryAddScoped<IConfigRepository, ConfigRepository>();
|
||||
@ -54,13 +54,12 @@ namespace EnvelopeGenerator.Application.Extensions
|
||||
services.AddAutoMapper(typeof(BasicDtoMappingProfile).Assembly);
|
||||
services.AddAutoMapper(typeof(UserMappingProfile).Assembly);
|
||||
|
||||
services.Configure<DispatcherConfig>(dispatcherConfigSection);
|
||||
services.Configure<MailConfig>(mailConfigSection);
|
||||
services.Configure<CodeGeneratorParams>(codeGeneratorConfigSection);
|
||||
services.Configure<EnvelopeReceiverCacheParams>(envelopeReceiverCacheParamsSection);
|
||||
services.Configure<TotpSmsParams>(totpSmsParamsSection);
|
||||
services.ConfigureByTypeName<DispatcherConfig>(config);
|
||||
services.ConfigureByTypeName<MailConfig>(config);
|
||||
services.ConfigureByTypeName<CodeGeneratorParams>(config);
|
||||
services.ConfigureByTypeName<TotpSmsParams>(config);
|
||||
|
||||
services.AddHttpClientService<SmsParams>(smsConfigSection);
|
||||
services.AddHttpClientService<SmsParams>(config.GetSection(nameof(SmsParams)));
|
||||
services.TryAddSingleton<ISmsSender, GTXSmsSender>();
|
||||
services.TryAddSingleton<IEnvelopeSmsService, EnvelopeSmsService>();
|
||||
services.TryAddSingleton<ICodeGenerator, CodeGenerator>();
|
||||
@ -69,12 +68,8 @@ namespace EnvelopeGenerator.Application.Extensions
|
||||
return services;
|
||||
}
|
||||
|
||||
public static IServiceCollection AddEnvelopeGenerator(this IServiceCollection services, IConfiguration config) => services.AddEnvelopeGenerator(
|
||||
dispatcherConfigSection: config.GetSection("DispatcherConfig"),
|
||||
mailConfigSection: config.GetSection("MailConfig"),
|
||||
smsConfigSection: config.GetSection("SmsConfig"),
|
||||
codeGeneratorConfigSection: config.GetSection("CodeGeneratorParams"),
|
||||
envelopeReceiverCacheParamsSection: config.GetSection("EnvelopeReceiverCacheParams"),
|
||||
totpSmsParamsSection: config.GetSection("TotpSmsParams"));
|
||||
//TODO: move to DigitalData.Core
|
||||
private static IServiceCollection ConfigureByTypeName<TOptions>(this IServiceCollection services, IConfiguration configuration) where TOptions : class
|
||||
=> services.Configure<TOptions>(configuration.GetSection(nameof(TOptions)));
|
||||
}
|
||||
}
|
||||
@ -23,6 +23,7 @@ using EnvelopeGenerator.Application.Extensions;
|
||||
using Microsoft.Extensions.Caching.Distributed;
|
||||
using System.Globalization;
|
||||
using Microsoft.Extensions.Options;
|
||||
using EnvelopeGenerator.Application.Configurations;
|
||||
|
||||
namespace EnvelopeGenerator.Web.Controllers
|
||||
{
|
||||
|
||||
@ -124,7 +124,7 @@
|
||||
"GTXMessagingConfig": {
|
||||
"AuthKey": "ep$?A!Gs"
|
||||
},
|
||||
"SmsConfig": {
|
||||
"SmsParams": {
|
||||
"Uri": "https://rest.gtx-messaging.net",
|
||||
"Path": "smsc/sendsms/f566f7e5-bdf2-4a9a-bf52-ed88215a432e/json",
|
||||
"Headers": {},
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user