Add configuration options and license key support
Updated `DependencyInjection.cs` to include support for `ConfigurationOptions`, enabling queued configuration actions and the ability to configure `RecActionOptions` via delegates or `IConfiguration`. Added `LuckyPennySoftwareLicenseKey` property to `ConfigurationOptions` and integrated it into `AddAutoMapper` setup. Introduced `ApplyConfigurations` method to process queued actions. Updated `using` directives to include necessary namespaces.
This commit is contained in:
@@ -1,4 +1,6 @@
|
|||||||
using Microsoft.Extensions.DependencyInjection;
|
using Microsoft.Extensions.Configuration;
|
||||||
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
|
using ReC.Application.Common.Options;
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
|
|
||||||
namespace ReC.Application;
|
namespace ReC.Application;
|
||||||
@@ -9,6 +11,7 @@ public static class DependencyInjection
|
|||||||
{
|
{
|
||||||
var configOpt = new ConfigurationOptions();
|
var configOpt = new ConfigurationOptions();
|
||||||
options.Invoke(configOpt);
|
options.Invoke(configOpt);
|
||||||
|
configOpt.ApplyConfigurations(services);
|
||||||
|
|
||||||
services.AddAutoMapper(cfg =>
|
services.AddAutoMapper(cfg =>
|
||||||
{
|
{
|
||||||
@@ -29,6 +32,29 @@ public static class DependencyInjection
|
|||||||
|
|
||||||
public class ConfigurationOptions
|
public class ConfigurationOptions
|
||||||
{
|
{
|
||||||
|
private readonly Queue<Action<IServiceCollection>> _configActions = new();
|
||||||
|
|
||||||
|
internal void ApplyConfigurations(IServiceCollection services)
|
||||||
|
{
|
||||||
|
while (_configActions.Count > 0)
|
||||||
|
{
|
||||||
|
var action = _configActions.Dequeue();
|
||||||
|
action(services);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public string? LuckyPennySoftwareLicenseKey { get; set; }
|
public string? LuckyPennySoftwareLicenseKey { get; set; }
|
||||||
|
|
||||||
|
public ConfigurationOptions ConfigureRecActions(Action<RecActionOptions> configure)
|
||||||
|
{
|
||||||
|
_configActions.Enqueue(services => services.Configure(configure));
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ConfigurationOptions ConfigureRecActions(IConfiguration configuration)
|
||||||
|
{
|
||||||
|
_configActions.Enqueue(services => services.Configure<RecActionOptions>(configuration));
|
||||||
|
return this;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user