/// <summary> /// Initializes a new instance of the <see cref="BlocklistSettingFilter"/> class. /// </summary> /// <param name="blockedSettings"> /// The collection of settings (and their child settings) that will be blocked. /// </param> /// <param name="innerFilter"> /// An optional setting filter that is applied if a setting is not a /// member of <see cref="BlockedSettings"/>. /// </param> public BlocklistSettingFilter(IEnumerable <string> blockedSettings, ISettingFilter innerFilter = null) { if (blockedSettings == null) { throw new ArgumentNullException(nameof(blockedSettings)); } _blockedSettings = new HashSet <string>(blockedSettings, StringComparer.OrdinalIgnoreCase); InnerFilter = innerFilter ?? NullSettingFilter.Instance; }
/// <summary> /// Initializes a new instance of the <see cref="MessagingConfigurationSource"/> class. /// </summary> /// <param name="receiver"> /// The <see cref="IReceiver"/> that will receive messages in order to change /// configuration values. /// </param> /// <param name="settingFilter"> /// The <see cref="ISettingFilter"/> that is applied to each setting of each /// received message. /// </param> public MessagingConfigurationSource(IReceiver receiver, ISettingFilter settingFilter = null) { if (receiver == null) { throw new ArgumentNullException(nameof(receiver)); } if (!ReferenceEquals(this, _validationCache.GetValue(receiver, r => this))) { throw new ArgumentException("The same instance of IReceiver cannot be used to create multiple instances of MessagingConfigurationSource.", nameof(receiver)); } if (receiver.MessageHandler != null) { throw new ArgumentException("The receiver is already started.", nameof(receiver)); } Receiver = receiver; SettingFilter = settingFilter; _cachedProvider = new Lazy <MessagingConfigurationProvider>(() => new MessagingConfigurationProvider(Receiver, SettingFilter)); }
internal MessagingConfigurationProvider(IReceiver receiver, ISettingFilter settingFilter) { Receiver = receiver; SettingFilter = settingFilter ?? NullSettingFilter.Instance; Receiver.Start(OnMessageReceivedAsync); }
/// <summary> /// Adds an <see cref="IConfigurationProvider"/> that reloads with changes /// specified in messages received from the <see cref="IReceiver"/>. /// </summary> /// <param name="builder">The <see cref="IConfigurationBuilder"/> to add to.</param> /// <param name="receiver"> /// The object that listens for messages that update configuration values. /// </param> /// <param name="settingFilter"> /// The <see cref="ISettingFilter"/> that is applied to each setting of each /// received message. /// </param> /// <returns>The <see cref="IConfigurationBuilder"/>.</returns> public static IConfigurationBuilder AddRockLibMessagingProvider(this IConfigurationBuilder builder, IReceiver receiver, ISettingFilter settingFilter = null) => builder.Add(new MessagingConfigurationSource(receiver, settingFilter));
/// <summary> /// Adds an <see cref="IConfigurationProvider"/> that reloads with changes /// specified in messages received from a new <see cref="IReceiver"/> with the /// specified name created from the built builder. /// </summary> /// <param name="builder">The <see cref="IConfigurationBuilder"/> to add to.</param> /// <param name="receiverName">The name of the receiver.</param> /// <param name="settingFilter"> /// The <see cref="ISettingFilter"/> that is applied to each setting of each /// received message. /// </param> /// <returns>The <see cref="IConfigurationBuilder"/>.</returns> /// <remarks> /// This is how the <see cref="IReceiver"/> is created: /// <code> /// builder.Build().GetSection("RockLib.Messaging").CreateReceiver(receiverName) /// </code> /// </remarks> public static IConfigurationBuilder AddRockLibMessagingProvider(this IConfigurationBuilder builder, string receiverName, ISettingFilter settingFilter = null) => builder.AddRockLibMessagingProvider(builder.Build().GetSection("RockLib.Messaging").CreateReceiver(receiverName), settingFilter);