fix(DIExtensions): ConsumerOptions-Eingabe in AddAuthService-Methode hinzugefügt, um Konsuemrn nach der Übernahme aus der Config arrangieren zu können.

- Standardiezd consumerKey Benennung
This commit is contained in:
Developer 02
2025-02-11 13:20:54 +01:00
parent 6694e4b626
commit 7873542aca
3 changed files with 18 additions and 20 deletions

View File

@@ -6,9 +6,19 @@ namespace DigitalData.Auth.API.Services;
public static class DIExtensions
{
public static IServiceCollection AddAuthService(this IServiceCollection services, IConfiguration configuration, string key = "Consumers")
public static IServiceCollection AddAuthService(this IServiceCollection services, IConfiguration configuration, Action<List<Consumer>>? consumerOptions = null)
{
var consumers = configuration.GetSection(key).Get<IEnumerable<Consumer>>() ?? throw new InvalidOperationException($"No Consumer list found in {key} in configuration.");
List<Consumer> consumers = new();
var consumerKey = $"{nameof(Consumer)}s";
if (configuration.GetSection(consumerKey).Get<IEnumerable<Consumer>>() is IEnumerable<Consumer> consumersFromConfig)
consumers.AddRange(consumersFromConfig);
consumerOptions?.Invoke(consumers);
if(consumers.Count == 0)
throw new InvalidOperationException($"No Consumer list found in {consumerKey} in configuration.");
services.AddSingleton(Options.Create(consumers));
services.AddSingleton<IConsumerService, ConfiguredConsumerService>();
services.AddSingleton<INotifier, Notifier>();