Skip to content

Commit ec9338a

Browse files
Use AzureBlobFileSystemOptions.ContainerRootPath as fallback in AzureBlobFileSystemImageCache
1 parent 1d790c7 commit ec9338a

File tree

2 files changed

+13
-13
lines changed

2 files changed

+13
-13
lines changed

src/Umbraco.StorageProviders.AzureBlob.ImageSharp/AzureBlobFileSystemImageCache.cs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,15 @@ namespace Umbraco.StorageProviders.AzureBlob.ImageSharp;
1515
/// </summary>
1616
public sealed class AzureBlobFileSystemImageCache : IImageCache
1717
{
18-
private readonly string? _containerRootPath;
1918
private BlobContainerClient _container;
19+
private string? _containerRootPath;
2020

2121
/// <summary>
2222
/// Initializes a new instance of the <see cref="AzureBlobFileSystemImageCache" /> class.
2323
/// </summary>
2424
/// <param name="options">The options.</param>
2525
/// <param name="name">The name.</param>
26-
/// <param name="containerRootPath">The container root path.</param>
26+
/// <param name="containerRootPath">The container root path (will use <see cref="AzureBlobFileSystemOptions.ContainerRootPath" /> if <c>null</c>).</param>
2727
/// <exception cref="ArgumentNullException"><paramref name="options" /> is <c>null</c>.</exception>
2828
public AzureBlobFileSystemImageCache(IOptionsMonitor<AzureBlobFileSystemOptions> options, string name, string? containerRootPath)
2929
{
@@ -32,19 +32,16 @@ public AzureBlobFileSystemImageCache(IOptionsMonitor<AzureBlobFileSystemOptions>
3232

3333
var fileSystemOptions = options.Get(name);
3434
_container = new BlobContainerClient(fileSystemOptions.ConnectionString, fileSystemOptions.ContainerName);
35+
_containerRootPath = GetContainerRootPath(containerRootPath, fileSystemOptions);
3536

3637
options.OnChange((options, changedName) =>
3738
{
3839
if (changedName == name)
3940
{
4041
_container = new BlobContainerClient(options.ConnectionString, options.ContainerName);
42+
_containerRootPath = GetContainerRootPath(containerRootPath, options);
4143
}
4244
});
43-
44-
if (!string.IsNullOrEmpty(containerRootPath))
45-
{
46-
_containerRootPath = containerRootPath.EnsureEndsWith('/');
47-
}
4845
}
4946

5047
/// <summary>
@@ -56,11 +53,14 @@ public AzureBlobFileSystemImageCache(IOptionsMonitor<AzureBlobFileSystemOptions>
5653
public AzureBlobFileSystemImageCache(BlobContainerClient blobContainerClient, string? containerRootPath)
5754
{
5855
_container = blobContainerClient ?? throw new ArgumentNullException(nameof(blobContainerClient));
56+
_containerRootPath = GetContainerRootPath(containerRootPath);
57+
}
5958

60-
if (!string.IsNullOrEmpty(containerRootPath))
61-
{
62-
_containerRootPath = containerRootPath.EnsureEndsWith('/');
63-
}
59+
private static string? GetContainerRootPath(string? containerRootPath, AzureBlobFileSystemOptions? options = null)
60+
{
61+
var path = containerRootPath ?? options?.ContainerRootPath;
62+
63+
return string.IsNullOrEmpty(path) ? null : path.EnsureEndsWith('/');
6464
}
6565

6666
/// <inheritdoc />

src/Umbraco.StorageProviders.AzureBlob.ImageSharp/DependencyInjection/AddAzureBlobImageSharpCacheExtensions.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public static IUmbracoBuilder AddAzureBlobImageSharpCache(this IUmbracoBuilder b
3030
/// </summary>
3131
/// <param name="builder">The <see cref="IUmbracoBuilder" />.</param>
3232
/// <param name="name">The name of the file system.</param>
33-
/// <param name="containerRootPath">The container root path.</param>
33+
/// <param name="containerRootPath">The container root path (will use <see cref="AzureBlobFileSystemOptions.ContainerRootPath" /> if <c>null</c>).</param>
3434
/// <returns>
3535
/// The <see cref="IUmbracoBuilder" />.
3636
/// </returns>
@@ -43,7 +43,7 @@ public static IUmbracoBuilder AddAzureBlobImageSharpCache(this IUmbracoBuilder b
4343
/// </summary>
4444
/// <param name="builder">The <see cref="IUmbracoBuilder" />.</param>
4545
/// <param name="name">The name of the file system.</param>
46-
/// <param name="containerRootPath">The container root path.</param>
46+
/// <param name="containerRootPath">The container root path (will use <see cref="AzureBlobFileSystemOptions.ContainerRootPath" /> if <c>null</c>).</param>
4747
/// <returns>
4848
/// The <see cref="IUmbracoBuilder" />.
4949
/// </returns>

0 commit comments

Comments
 (0)