using System; using System.Collections.Generic; using System.Configuration; using Kreta.Core.MessageBroker.Azure.EventHub.Client.Configuration; namespace Kreta.MessageBroker.Configuration { /// /// Message client configuration section /// public class MessageBrokerConfigurationSection : ConfigurationSection, IMessageBrokerConfiguration, IAzureEventHubClientsConfiguration { /// /// Name of section /// const string SectionName = "MessageBroker"; /// /// The instance /// static Lazy instance; /// /// Gets the instance. /// /// /// The instance. /// public static MessageBrokerConfigurationSection Instance { get { return instance.Value; } } /// /// Clients /// [ConfigurationProperty(nameof(Clients))] [ConfigurationCollection(typeof(MessageClientConfigurationElement))] public MessageClientConfigurationElementCollection Clients { get { return (MessageClientConfigurationElementCollection)base[nameof(Clients)]; } } /// /// Clients /// [ConfigurationProperty(nameof(EventHubs))] [ConfigurationCollection(typeof(EventHubClientConfigurationElement))] public EventHubClientConfigurationElementCollection EventHubs { get { return (EventHubClientConfigurationElementCollection)base[nameof(EventHubs)]; } } IEnumerable IAzureEventHubClientsConfiguration.EventHubs => this.EventHubs; /// /// Initializes a new instance of the class. /// static MessageBrokerConfigurationSection() { instance = new Lazy(() => { var section = (MessageBrokerConfigurationSection)ConfigurationManager.GetSection(SectionName); if (section == null) { throw new ConfigurationErrorsException($"{SectionName} configuration section was not found"); } return section; }); } } }