@@ -17,7 +17,6 @@ namespace Umbraco.StorageProviders.AzureBlob.Imaging
17
17
public class AzureBlobFileSystemImageCache : IImageCache
18
18
{
19
19
private const string _cachePath = "cache/" ;
20
- private readonly string _name ;
21
20
private BlobContainerClient _container ;
22
21
23
22
/// <summary>
@@ -33,19 +32,28 @@ public AzureBlobFileSystemImageCache(IOptionsMonitor<AzureBlobFileSystemOptions>
33
32
/// </summary>
34
33
/// <param name="name">The name.</param>
35
34
/// <param name="options">The options.</param>
36
- /// <exception cref="System.ArgumentNullException">options
37
- /// or
38
- /// name</exception>
39
35
protected AzureBlobFileSystemImageCache ( string name , IOptionsMonitor < AzureBlobFileSystemOptions > options )
40
36
{
41
37
if ( options == null ) throw new ArgumentNullException ( nameof ( options ) ) ;
42
38
43
- _name = name ?? throw new ArgumentNullException ( nameof ( name ) ) ;
44
-
45
39
var fileSystemOptions = options . Get ( name ) ;
46
40
_container = new BlobContainerClient ( fileSystemOptions . ConnectionString , fileSystemOptions . ContainerName ) ;
47
41
48
- options . OnChange ( OptionsOnChange ) ;
42
+ options . OnChange ( ( options , changedName ) =>
43
+ {
44
+ if ( changedName != name ) return ;
45
+
46
+ _container = new BlobContainerClient ( options . ConnectionString , options . ContainerName ) ;
47
+ } ) ;
48
+ }
49
+
50
+ /// <summary>
51
+ /// Initializes a new instance of the <see cref="AzureBlobFileSystemImageCache" /> class.
52
+ /// </summary>
53
+ /// <param name="blobContainerClient">The blob container client.</param>
54
+ public AzureBlobFileSystemImageCache ( BlobContainerClient blobContainerClient )
55
+ {
56
+ _container = blobContainerClient ?? throw new ArgumentNullException ( nameof ( blobContainerClient ) ) ;
49
57
}
50
58
51
59
/// <inheritdoc />
@@ -68,12 +76,5 @@ public async Task SetAsync(string key, Stream stream, ImageCacheMetadata metadat
68
76
69
77
await blob . UploadAsync ( stream , metadata : metadata . ToDictionary ( ) ) . ConfigureAwait ( false ) ;
70
78
}
71
-
72
- private void OptionsOnChange ( AzureBlobFileSystemOptions options , string name )
73
- {
74
- if ( name != _name ) return ;
75
-
76
- _container = new BlobContainerClient ( options . ConnectionString , options . ContainerName ) ;
77
- }
78
79
}
79
80
}
0 commit comments