kreta/Kreta.MessageBroker/Configuration/MessageBrokerConfigurationSection.cs
2024-03-13 00:33:46 +01:00

83 lines
2.6 KiB
C#

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