diff --git a/src/ImageSharp.Web.Providers.Azure/Caching/AzureBlobStorageCache.cs b/src/ImageSharp.Web.Providers.Azure/Caching/AzureBlobStorageCache.cs
index 05e8190c..089062dd 100644
--- a/src/ImageSharp.Web.Providers.Azure/Caching/AzureBlobStorageCache.cs
+++ b/src/ImageSharp.Web.Providers.Azure/Caching/AzureBlobStorageCache.cs
@@ -22,12 +22,15 @@ public class AzureBlobStorageCache : IImageCache
/// Initializes a new instance of the class.
///
/// The cache options.
- public AzureBlobStorageCache(IOptions cacheOptions)
+ /// The current service provider.
+ public AzureBlobStorageCache(IOptions cacheOptions, IServiceProvider serviceProvider)
{
Guard.NotNull(cacheOptions, nameof(cacheOptions));
AzureBlobStorageCacheOptions options = cacheOptions.Value;
- this.container = new BlobContainerClient(options.ConnectionString, options.ContainerName);
+ this.container = options.BlobContainerClientProvider == null
+ ? new BlobContainerClient(options.ConnectionString, options.ContainerName)
+ : options.BlobContainerClientProvider(options, serviceProvider);
this.cacheFolder = string.IsNullOrEmpty(options.CacheFolder)
? string.Empty
: options.CacheFolder.Trim().Trim('/') + '/';
diff --git a/src/ImageSharp.Web.Providers.Azure/Caching/AzureBlobStorageCacheOptions.cs b/src/ImageSharp.Web.Providers.Azure/Caching/AzureBlobStorageCacheOptions.cs
index 9db937a9..c74ae302 100644
--- a/src/ImageSharp.Web.Providers.Azure/Caching/AzureBlobStorageCacheOptions.cs
+++ b/src/ImageSharp.Web.Providers.Azure/Caching/AzureBlobStorageCacheOptions.cs
@@ -1,6 +1,8 @@
// Copyright (c) Six Labors.
// Licensed under the Six Labors Split License.
+using Azure.Storage.Blobs;
+
namespace SixLabors.ImageSharp.Web.Caching.Azure;
///
@@ -8,6 +10,11 @@ namespace SixLabors.ImageSharp.Web.Caching.Azure;
///
public class AzureBlobStorageCacheOptions
{
+ ///
+ /// Gets or sets a custom Azure BlobContainerClient provider
+ ///
+ public Func? BlobContainerClientProvider { get; set; } = null!;
+
///
/// Gets or sets the Azure Blob Storage connection string.
///
diff --git a/src/ImageSharp.Web.Providers.Azure/Providers/AzureBlobStorageImageProvider.cs b/src/ImageSharp.Web.Providers.Azure/Providers/AzureBlobStorageImageProvider.cs
index 02c48797..41da7281 100644
--- a/src/ImageSharp.Web.Providers.Azure/Providers/AzureBlobStorageImageProvider.cs
+++ b/src/ImageSharp.Web.Providers.Azure/Providers/AzureBlobStorageImageProvider.cs
@@ -41,9 +41,11 @@ private readonly Dictionary containers
///
/// The blob storage options.
/// Contains various format helper methods based on the current configuration.
+ /// The current service provider
public AzureBlobStorageImageProvider(
IOptions storageOptions,
- FormatUtilities formatUtilities)
+ FormatUtilities formatUtilities,
+ IServiceProvider serviceProvider)
{
Guard.NotNull(storageOptions, nameof(storageOptions));
@@ -51,9 +53,11 @@ public AzureBlobStorageImageProvider(
foreach (AzureBlobContainerClientOptions container in storageOptions.Value.BlobContainers)
{
- this.containers.Add(
- container.ContainerName!,
- new BlobContainerClient(container.ConnectionString, container.ContainerName));
+ BlobContainerClient containerClient = container.BlobContainerClientProvider == null
+ ? new BlobContainerClient(container.ConnectionString, container.ContainerName)
+ : container.BlobContainerClientProvider(container, serviceProvider);
+
+ this.containers.Add(container.ContainerName!, containerClient);
}
}
diff --git a/src/ImageSharp.Web.Providers.Azure/Providers/AzureBlobStorageImageProviderOptions.cs b/src/ImageSharp.Web.Providers.Azure/Providers/AzureBlobStorageImageProviderOptions.cs
index 58743d83..aa5e3164 100644
--- a/src/ImageSharp.Web.Providers.Azure/Providers/AzureBlobStorageImageProviderOptions.cs
+++ b/src/ImageSharp.Web.Providers.Azure/Providers/AzureBlobStorageImageProviderOptions.cs
@@ -1,6 +1,8 @@
// Copyright (c) Six Labors.
// Licensed under the Six Labors Split License.
+using Azure.Storage.Blobs;
+
namespace SixLabors.ImageSharp.Web.Providers.Azure;
///
@@ -19,6 +21,11 @@ public class AzureBlobStorageImageProviderOptions
///
public class AzureBlobContainerClientOptions
{
+ ///
+ /// Gets or sets a custom Azure BlobServiceClient provider
+ ///
+ public Func? BlobContainerClientProvider { get; set; } = null!;
+
///
/// Gets or sets the Azure Blob Storage connection string.
///
diff --git a/tests/ImageSharp.Web.Tests/TestUtilities/AzureBlobStorageImageProviderFactory.cs b/tests/ImageSharp.Web.Tests/TestUtilities/AzureBlobStorageImageProviderFactory.cs
index b01ad5b3..95836089 100644
--- a/tests/ImageSharp.Web.Tests/TestUtilities/AzureBlobStorageImageProviderFactory.cs
+++ b/tests/ImageSharp.Web.Tests/TestUtilities/AzureBlobStorageImageProviderFactory.cs
@@ -20,7 +20,7 @@ public static AzureBlobStorageImageProvider Create(IServiceProvider services)
FormatUtilities utilities = services.GetRequiredService();
InitializeAzureStorage(services, options.Value);
- return new AzureBlobStorageImageProvider(options, utilities);
+ return new AzureBlobStorageImageProvider(options, utilities, services);
}
private static void InitializeAzureStorage(IServiceProvider services, AzureBlobStorageImageProviderOptions options)