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 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
|
//Inject CRUD Service and repositoriesad
|
||||||
services.TryAddScoped<IConfigRepository, ConfigRepository>();
|
services.TryAddScoped<IConfigRepository, ConfigRepository>();
|
||||||
@ -54,13 +54,12 @@ namespace EnvelopeGenerator.Application.Extensions
|
|||||||
services.AddAutoMapper(typeof(BasicDtoMappingProfile).Assembly);
|
services.AddAutoMapper(typeof(BasicDtoMappingProfile).Assembly);
|
||||||
services.AddAutoMapper(typeof(UserMappingProfile).Assembly);
|
services.AddAutoMapper(typeof(UserMappingProfile).Assembly);
|
||||||
|
|
||||||
services.Configure<DispatcherConfig>(dispatcherConfigSection);
|
services.ConfigureByTypeName<DispatcherConfig>(config);
|
||||||
services.Configure<MailConfig>(mailConfigSection);
|
services.ConfigureByTypeName<MailConfig>(config);
|
||||||
services.Configure<CodeGeneratorParams>(codeGeneratorConfigSection);
|
services.ConfigureByTypeName<CodeGeneratorParams>(config);
|
||||||
services.Configure<EnvelopeReceiverCacheParams>(envelopeReceiverCacheParamsSection);
|
services.ConfigureByTypeName<TotpSmsParams>(config);
|
||||||
services.Configure<TotpSmsParams>(totpSmsParamsSection);
|
|
||||||
|
|
||||||
services.AddHttpClientService<SmsParams>(smsConfigSection);
|
services.AddHttpClientService<SmsParams>(config.GetSection(nameof(SmsParams)));
|
||||||
services.TryAddSingleton<ISmsSender, GTXSmsSender>();
|
services.TryAddSingleton<ISmsSender, GTXSmsSender>();
|
||||||
services.TryAddSingleton<IEnvelopeSmsService, EnvelopeSmsService>();
|
services.TryAddSingleton<IEnvelopeSmsService, EnvelopeSmsService>();
|
||||||
services.TryAddSingleton<ICodeGenerator, CodeGenerator>();
|
services.TryAddSingleton<ICodeGenerator, CodeGenerator>();
|
||||||
@ -69,12 +68,8 @@ namespace EnvelopeGenerator.Application.Extensions
|
|||||||
return services;
|
return services;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static IServiceCollection AddEnvelopeGenerator(this IServiceCollection services, IConfiguration config) => services.AddEnvelopeGenerator(
|
//TODO: move to DigitalData.Core
|
||||||
dispatcherConfigSection: config.GetSection("DispatcherConfig"),
|
private static IServiceCollection ConfigureByTypeName<TOptions>(this IServiceCollection services, IConfiguration configuration) where TOptions : class
|
||||||
mailConfigSection: config.GetSection("MailConfig"),
|
=> services.Configure<TOptions>(configuration.GetSection(nameof(TOptions)));
|
||||||
smsConfigSection: config.GetSection("SmsConfig"),
|
|
||||||
codeGeneratorConfigSection: config.GetSection("CodeGeneratorParams"),
|
|
||||||
envelopeReceiverCacheParamsSection: config.GetSection("EnvelopeReceiverCacheParams"),
|
|
||||||
totpSmsParamsSection: config.GetSection("TotpSmsParams"));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -23,6 +23,7 @@ using EnvelopeGenerator.Application.Extensions;
|
|||||||
using Microsoft.Extensions.Caching.Distributed;
|
using Microsoft.Extensions.Caching.Distributed;
|
||||||
using System.Globalization;
|
using System.Globalization;
|
||||||
using Microsoft.Extensions.Options;
|
using Microsoft.Extensions.Options;
|
||||||
|
using EnvelopeGenerator.Application.Configurations;
|
||||||
|
|
||||||
namespace EnvelopeGenerator.Web.Controllers
|
namespace EnvelopeGenerator.Web.Controllers
|
||||||
{
|
{
|
||||||
|
|||||||
@ -124,7 +124,7 @@
|
|||||||
"GTXMessagingConfig": {
|
"GTXMessagingConfig": {
|
||||||
"AuthKey": "ep$?A!Gs"
|
"AuthKey": "ep$?A!Gs"
|
||||||
},
|
},
|
||||||
"SmsConfig": {
|
"SmsParams": {
|
||||||
"Uri": "https://rest.gtx-messaging.net",
|
"Uri": "https://rest.gtx-messaging.net",
|
||||||
"Path": "smsc/sendsms/f566f7e5-bdf2-4a9a-bf52-ed88215a432e/json",
|
"Path": "smsc/sendsms/f566f7e5-bdf2-4a9a-bf52-ed88215a432e/json",
|
||||||
"Headers": {},
|
"Headers": {},
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user