public static IServiceCollection AddAzureServiceBusMessageBus()

in src/Relecloud.Messaging/ServiceBus/AzureServiceBusMessageBusExtensions.cs [24:50]


    public static IServiceCollection AddAzureServiceBusMessageBus(this IServiceCollection services, string configSectionPath, TokenCredential? azureCredential)
    {
        services.AddMessageBusOptions(configSectionPath);

        services.AddSingleton<IMessageBus, AzureServiceBusMessageBus>();

        // ServiceBusClient is thread-safe and can be reused for the lifetime of the application.
        services.AddSingleton(sp =>
        {
            var options = sp.GetRequiredService<IOptions<MessageBusOptions>>().Value;
            var clientOptions = new ServiceBusClientOptions
            {
                RetryOptions = new ServiceBusRetryOptions
                {
                    Mode = ServiceBusRetryMode.Exponential,
                    MaxRetries = options.MaxRetries,
                    Delay = TimeSpan.FromSeconds(options.BaseDelaySecondsBetweenRetries),
                    MaxDelay = TimeSpan.FromSeconds(options.MaxDelaySeconds),
                    TryTimeout = TimeSpan.FromSeconds(options.TryTimeoutSeconds)
                }
            };

            return new ServiceBusClient(options.Host, azureCredential ?? new DefaultAzureCredential(), clientOptions);
        });

        return services;
    }