/// <summary> /// Initializes a new instance of the <see cref="AzureServiceBusMessagePumpSettings"/> class. /// </summary> /// <param name="entityName">The name of the entity to process.</param> /// <param name="subscriptionName">The name of the subscription to process.</param> /// <param name="serviceBusEntity">The entity type of the Azure Service Bus.</param> /// <param name="getConnectionStringFromConfigurationFunc">The function to look up the connection string from the configuration.</param> /// <param name="getConnectionStringFromSecretFunc">Function to look up the connection string from the secret store.</param> /// <param name="options">The options that influence the behavior of the <see cref="AzureServiceBusMessagePump"/>.</param> /// <param name="serviceProvider">The collection of services to use during the lifetime of the <see cref="AzureServiceBusMessagePump"/>.</param> /// <exception cref="ArgumentNullException">Thrown when the <paramref name="options"/> or <paramref name="serviceProvider"/> is <c>null</c>.</exception> /// <exception cref="ArgumentException"> /// Thrown when the <paramref name="getConnectionStringFromConfigurationFunc"/> nor the <paramref name="getConnectionStringFromSecretFunc"/> is available. /// </exception> public AzureServiceBusMessagePumpSettings( string entityName, string subscriptionName, ServiceBusEntityType serviceBusEntity, Func <IConfiguration, string> getConnectionStringFromConfigurationFunc, Func <ISecretProvider, Task <string> > getConnectionStringFromSecretFunc, AzureServiceBusMessagePumpOptions options, IServiceProvider serviceProvider) { Guard.For <ArgumentException>( () => getConnectionStringFromConfigurationFunc is null && getConnectionStringFromSecretFunc is null, $"Requires an function that determines the connection string from either either an {nameof(IConfiguration)} or {nameof(ISecretProvider)} instance"); Guard.NotNull(options, nameof(options), "Requires message pump options that influence the behavior of the message pump"); Guard.NotNull(serviceProvider, nameof(serviceProvider), "Requires a service provider to get additional registered services during the lifetime of the message pump"); Guard.For <ArgumentException>( () => !Enum.IsDefined(typeof(ServiceBusEntityType), serviceBusEntity), $"Azure Service Bus entity '{serviceBusEntity}' is not defined in the '{nameof(ServiceBusEntityType)}' enumeration"); Guard.For <ArgumentOutOfRangeException>( () => serviceBusEntity is ServiceBusEntityType.Unknown, "Azure Service Bus entity type 'Unknown' is not supported here"); _serviceProvider = serviceProvider; _getConnectionStringFromConfigurationFunc = getConnectionStringFromConfigurationFunc; _getConnectionStringFromSecretFunc = getConnectionStringFromSecretFunc; EntityName = entityName; SubscriptionName = subscriptionName; ServiceBusEntity = serviceBusEntity; Options = options; }
/// <summary> /// Initializes a new instance of the <see cref="AzureServiceBusMessagePumpSettings"/> class. /// </summary> /// <param name="entityName">The name of the entity to process.</param> /// <param name="subscriptionName">The name of the subscription to process.</param> /// <param name="serviceBusEntity">The entity type of the Azure Service Bus.</param> /// <param name="serviceBusNamespace"> /// The Service Bus namespace to connect to. This is likely to be similar to <c>{yournamespace}.servicebus.windows.net</c>. /// </param> /// <param name="tokenCredential">The client credentials to authenticate with the Azure Service Bus.</param> /// <param name="options">The options that influence the behavior of the <see cref="AzureServiceBusMessagePump"/>.</param> /// <param name="serviceProvider">The collection of services to use during the lifetime of the <see cref="AzureServiceBusMessagePump"/>.</param> /// <exception cref="ArgumentNullException"> /// Thrown when the <paramref name="options"/>, <paramref name="serviceProvider"/>, or <paramref name="tokenCredential"/> is <c>null</c>. /// </exception> /// <exception cref="ArgumentException"> /// Thrown when the <paramref name="serviceBusNamespace"/> is blank or the <paramref name="serviceBusEntity"/> is outside the bounds of the enumeration. /// </exception> /// <exception cref="ArgumentOutOfRangeException"> /// Thrown when the <paramref name="serviceBusEntity"/> represents the unsupported value <see cref="ServiceBusEntityType.Unknown"/>. /// </exception> public AzureServiceBusMessagePumpSettings( string entityName, string subscriptionName, ServiceBusEntityType serviceBusEntity, string serviceBusNamespace, TokenCredential tokenCredential, AzureServiceBusMessagePumpOptions options, IServiceProvider serviceProvider) { Guard.NotNull(options, nameof(options), "Requires message pump options that influence the behavior of the message pump"); Guard.NotNull(serviceProvider, nameof(serviceProvider), "Requires a service provider to get additional registered services during the lifetime of the message pump"); Guard.NotNull(tokenCredential, nameof(tokenCredential), "Requires a token credential instance to authenticate with the Azure Service Bus"); Guard.NotNullOrWhitespace(entityName, nameof(entityName), "Requires a non-blank entity name for the Azure Service Bus when using the token credentials"); Guard.NotNullOrWhitespace(serviceBusNamespace, nameof(serviceBusNamespace), "Requires a non-blank fully qualified Azure Service Bus namespace when using the token credentials"); Guard.For <ArgumentException>(() => !Enum.IsDefined(typeof(ServiceBusEntityType), serviceBusEntity), $"Azure Service Bus entity '{serviceBusEntity}' is not defined in the '{nameof(ServiceBusEntityType)}' enumeration"); Guard.For <ArgumentOutOfRangeException>(() => serviceBusEntity is ServiceBusEntityType.Unknown, "Azure Service Bus entity type 'Unknown' is not supported here"); _serviceProvider = serviceProvider; _tokenCredential = tokenCredential; EntityName = entityName; SubscriptionName = subscriptionName; ServiceBusEntity = serviceBusEntity; Options = options; if (serviceBusNamespace.EndsWith(".servicebus.windows.net")) { FullyQualifiedNamespace = serviceBusNamespace; } else { FullyQualifiedNamespace = serviceBusNamespace + ".servicebus.windows.net"; } }