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:
@@ -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>();
|
||||
|
||||
Reference in New Issue
Block a user