diff --git a/src/ReC.Application/DependencyInjection.cs b/src/ReC.Application/DependencyInjection.cs index 070a261..239eda9 100644 --- a/src/ReC.Application/DependencyInjection.cs +++ b/src/ReC.Application/DependencyInjection.cs @@ -11,6 +11,9 @@ public static class DependencyInjection { var configOpt = new ConfigurationOptions(); options.Invoke(configOpt); + + configOpt.EnsureRequiredServices(); + configOpt.ApplyConfigurations(services); services.AddAutoMapper(cfg => @@ -34,6 +37,21 @@ public static class DependencyInjection { private readonly Queue> _configActions = new(); + private readonly Dictionary _requiredServices = new() + { + { nameof(ConfigureRecActions), false }, + { nameof(LuckyPennySoftwareLicenseKey), false } + }; + + internal void EnsureRequiredServices() + { + var missingServices = _requiredServices + .Where(kvp => !kvp.Value) + .Select(kvp => kvp.Key.Replace("Configure", string.Empty)); + if (missingServices.Any()) + throw new InvalidOperationException($"The following required services were not configured: {string.Join(", ", missingServices)}"); + } + internal void ApplyConfigurations(IServiceCollection services) { while (_configActions.Count > 0) @@ -43,17 +61,29 @@ public static class DependencyInjection } } - public string? LuckyPennySoftwareLicenseKey { get; set; } + private string? _luckyPennySoftwareLicenseKey; + + public string? LuckyPennySoftwareLicenseKey + { + get => _luckyPennySoftwareLicenseKey; + set + { + _luckyPennySoftwareLicenseKey = value; + _requiredServices[nameof(LuckyPennySoftwareLicenseKey)] = true; + } + } public ConfigurationOptions ConfigureRecActions(Action configure) { _configActions.Enqueue(services => services.Configure(configure)); + _requiredServices[nameof(ConfigureRecActions)] = true; return this; } public ConfigurationOptions ConfigureRecActions(IConfiguration configuration) { _configActions.Enqueue(services => services.Configure(configuration)); + _requiredServices[nameof(ConfigureRecActions)] = true; return this; } }