/// <summary> /// Initializes a new instance of <see cref="Registry"/>. /// </summary> /// <param name="settings">Configuration settings for registry initialization.</param> /// <param name="stepFactory">A factory to create steps from settings.</param> /// <param name="processorFactory">A factory to create processors from settings.</param> /// <param name="policyFactory">A factory to create http client policies from settings.</param> /// <param name="clientFactory">A factory to create http client configurations from settings.</param> /// <param name="logger">The <see cref="ILogger"/> instance to use for logging.</param> /// <param name="loggerFactory">The <see cref="ILoggerFactory"/> instance to use for initializing loggers for created objects.</param> public Registry(IRegistrySettings settings, IConfigFactory <IStep> stepFactory, IConfigFactory <IProcessor> processorFactory, IConfigFactory <IAsyncPolicy <HttpResponseMessage> > policyFactory, IConfigFactory <ClientConfig> clientFactory, ILogger <Registry> logger, ILoggerFactory loggerFactory) { _ = settings ?? throw new ArgumentNullException(nameof(settings)); _ = stepFactory ?? throw new ArgumentNullException(nameof(stepFactory)); _ = processorFactory ?? throw new ArgumentNullException(nameof(processorFactory)); _ = policyFactory ?? throw new ArgumentNullException(nameof(policyFactory)); _ = clientFactory ?? throw new ArgumentNullException(nameof(clientFactory)); log = logger ?? throw new ArgumentNullException(nameof(logger)); _ = loggerFactory ?? throw new ArgumentNullException(nameof(loggerFactory)); InitializeFromSettings(settings, ProcessorsSection, out processors, (s) => processorFactory.Create(s)); InitializeFromSettings(settings, StepsSection, out steps, (s) => stepFactory.Create(s)); InitializeFromSettings(settings, PoliciesSection, out policies, (s) => policyFactory.Create(s)); InitializeFromSettings(settings, ClientsSection, out clients, (s) => clientFactory.Create(s)); foreach (var policy in policies) { log.LogDebug("{Policy} added from {Setting}", policy.Value?.GetType()?.Name, policy.Key); PolicyRegistry.Add(policy.Key, policy.Value); } simpleClientFactory = new SimpleHttpClientFactory(clients, loggerFactory.CreateLogger <SimpleHttpClientFactory>()); }
public IConfig GetConfig(string namespaceName) { IConfig config; _configs.TryGetValue(namespaceName, out config); if (config == null) { lock (this) { _configs.TryGetValue(namespaceName, out config); if (config == null) { IConfigFactory factory = _factoryManager.GetFactory(namespaceName); config = factory.Create(namespaceName); _configs[namespaceName] = config; } } } return(config); }