@@ -15,15 +15,15 @@ namespace Umbraco.StorageProviders.AzureBlob.ImageSharp;
15
15
/// </summary>
16
16
public sealed class AzureBlobFileSystemImageCache : IImageCache
17
17
{
18
- private readonly string ? _containerRootPath ;
19
18
private BlobContainerClient _container ;
19
+ private string ? _containerRootPath ;
20
20
21
21
/// <summary>
22
22
/// Initializes a new instance of the <see cref="AzureBlobFileSystemImageCache" /> class.
23
23
/// </summary>
24
24
/// <param name="options">The options.</param>
25
25
/// <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>
27
27
/// <exception cref="ArgumentNullException"><paramref name="options" /> is <c>null</c>.</exception>
28
28
public AzureBlobFileSystemImageCache ( IOptionsMonitor < AzureBlobFileSystemOptions > options , string name , string ? containerRootPath )
29
29
{
@@ -32,19 +32,16 @@ public AzureBlobFileSystemImageCache(IOptionsMonitor<AzureBlobFileSystemOptions>
32
32
33
33
var fileSystemOptions = options . Get ( name ) ;
34
34
_container = new BlobContainerClient ( fileSystemOptions . ConnectionString , fileSystemOptions . ContainerName ) ;
35
+ _containerRootPath = GetContainerRootPath ( containerRootPath , fileSystemOptions ) ;
35
36
36
37
options . OnChange ( ( options , changedName ) =>
37
38
{
38
39
if ( changedName == name )
39
40
{
40
41
_container = new BlobContainerClient ( options . ConnectionString , options . ContainerName ) ;
42
+ _containerRootPath = GetContainerRootPath ( containerRootPath , options ) ;
41
43
}
42
44
} ) ;
43
-
44
- if ( ! string . IsNullOrEmpty ( containerRootPath ) )
45
- {
46
- _containerRootPath = containerRootPath . EnsureEndsWith ( '/' ) ;
47
- }
48
45
}
49
46
50
47
/// <summary>
@@ -56,11 +53,14 @@ public AzureBlobFileSystemImageCache(IOptionsMonitor<AzureBlobFileSystemOptions>
56
53
public AzureBlobFileSystemImageCache ( BlobContainerClient blobContainerClient , string ? containerRootPath )
57
54
{
58
55
_container = blobContainerClient ?? throw new ArgumentNullException ( nameof ( blobContainerClient ) ) ;
56
+ _containerRootPath = GetContainerRootPath ( containerRootPath ) ;
57
+ }
59
58
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 ( '/' ) ;
64
64
}
65
65
66
66
/// <inheritdoc />
0 commit comments