Refactor configuration handling
Refactored `MessagingServiceApplicationConfiguration` to simplify the tracking of the LuckyPennySoft license key configuration by replacing the `_configured` tuple with a boolean. Removed email account configuration methods from this class. Updated `MessagingServiceInfrastructureConfiguration` to introduce a new `_configured` tuple for tracking `RabbitMqConnectionFactory` and `EmailAccounts` configurations. Added methods for configuring email accounts and updated the `EnsureRabbitMqConnectionFactoryAdded` method to include email account checks. Changed the namespace of `EmailAccountsOptions.cs` to `DigitalData.MessagingService.Infrastructure.Options`. Modified `Program.cs` to include email account configuration in the infrastructure setup. Added new files `DependencyInjectionExtensions.cs` and `MessagingServiceConfiguration.cs` as placeholders for future extensions, wrapped in `#if NET` directives. Removed an `<ItemGroup>` from `DigitalData.MessagingService.Infrastructure.csproj` and updated `DigitalData.MessagingService.Client.csproj` for XML compliance.
This commit is contained in:
@@ -1,5 +1,4 @@
|
||||
#if NET
|
||||
using DigitalData.MessagingService.Application.Common.Options;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
|
||||
@@ -9,7 +8,7 @@ public partial class MessagingServiceApplicationConfiguration
|
||||
{
|
||||
private IServiceCollection Services { get; }
|
||||
|
||||
private (bool LuckyPennySoftLicenseKey, bool EmailAccounts) _configured = (LuckyPennySoftLicenseKey: false, EmailAccounts: false);
|
||||
private bool _luckyPennySoftLicenseKeyAdded = false;
|
||||
|
||||
internal MessagingServiceApplicationConfiguration(IServiceCollection services)
|
||||
{
|
||||
@@ -18,14 +17,10 @@ public partial class MessagingServiceApplicationConfiguration
|
||||
|
||||
internal void EnsureConfigured()
|
||||
{
|
||||
if (!_configured.LuckyPennySoftLicenseKey)
|
||||
if (!_luckyPennySoftLicenseKeyAdded)
|
||||
{
|
||||
throw new InvalidOperationException("LuckyPennySoftLicenseKey is not configured. Please call SetLuckyPennySoftLicenseKey() or SetLuckyPennySoftLicenseKey(IConfiguration) in DI configuration.");
|
||||
}
|
||||
if (!_configured.EmailAccounts)
|
||||
{
|
||||
throw new InvalidOperationException("EmailAccountsOptions is not configured. Please call ConfigureEmailAccountsOptions() or ConfigureEmailAccounts(IConfiguration) in DI configuration.");
|
||||
}
|
||||
}
|
||||
|
||||
#region LuckyPennySoftLicenseKey
|
||||
@@ -37,7 +32,7 @@ public partial class MessagingServiceApplicationConfiguration
|
||||
throw new InvalidOperationException("LuckyPennySoftLicenseKey is not configured. Please call SetLuckyPennySoftLicenseKey() or SetLuckyPennySoftLicenseKey(IConfiguration) in DI configuration.");
|
||||
|
||||
LuckyPennySoftLicenseKey = licenseKey;
|
||||
_configured.LuckyPennySoftLicenseKey = true;
|
||||
_luckyPennySoftLicenseKeyAdded = true;
|
||||
return this;
|
||||
}
|
||||
|
||||
@@ -46,33 +41,5 @@ public partial class MessagingServiceApplicationConfiguration
|
||||
return SetLuckyPennySoftLicenseKey(configuration.GetValue<string>(key) ?? string.Empty);
|
||||
}
|
||||
#endregion LuckyPennySoftLicenseKey
|
||||
|
||||
#region EmailAccountsOptions
|
||||
/// <summary>
|
||||
/// Ignores whether EmailAccountsOptions is configured or not. Use this method if you just want to publish messages to the messaging service; not to send
|
||||
/// emails. If you want to consume the messaging service to send emails, you must configure EmailAccountsOptions using ConfigureEmailAccountsOptions() or
|
||||
/// ConfigureEmailAccounts(IConfiguration).
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public MessagingServiceApplicationConfiguration PublishOnly()
|
||||
{
|
||||
_configured.EmailAccounts = true;
|
||||
return this;
|
||||
}
|
||||
|
||||
public MessagingServiceApplicationConfiguration ConfigureEmailAccountsOptions(Action<EmailAccountsOptions> configureOptions)
|
||||
{
|
||||
Services.Configure(configureOptions);
|
||||
_configured.EmailAccounts = true;
|
||||
return this;
|
||||
}
|
||||
|
||||
public MessagingServiceApplicationConfiguration ConfigureEmailAccounts(IConfiguration configuration, string sectionName = EmailAccountsOptions.SectionName)
|
||||
{
|
||||
Services.Configure<EmailAccountsOptions>(configuration.GetSection(sectionName));
|
||||
_configured.EmailAccounts = true;
|
||||
return this;
|
||||
}
|
||||
#endregion EmailAccountsOptions
|
||||
}
|
||||
#endif
|
||||
Reference in New Issue
Block a user