1
1
// Licensed to the .NET Foundation under one or more agreements.
2
2
// The .NET Foundation licenses this file to you under the MIT license.
3
3
4
+ using System . Diagnostics . CodeAnalysis ;
5
+ using System . Runtime . CompilerServices ;
4
6
using Aspire . Hosting . ApplicationModel ;
5
7
using Aspire . Hosting . Azure ;
6
8
using Azure . Provisioning ;
@@ -11,12 +13,19 @@ namespace Aspire.Hosting;
11
13
/// A resource that represents an Azure Blob Storage container.
12
14
/// </summary>
13
15
/// <param name="name">The name of the resource.</param>
14
- /// <param name="blobStorage">The <see cref="AzureBlobStorageResource"/> that the resource is stored in.</param>
15
- public class AzureBlobStorageContainerResource ( string name , AzureBlobStorageResource blobStorage ) : Resource ( name ) ,
16
+ /// <param name="blobContainerName">The name of the blob container.</param>
17
+ /// <param name="parent">The <see cref="AzureBlobStorageResource"/> that the resource is stored in.</param>
18
+ public class AzureBlobStorageContainerResource ( string name , string blobContainerName , AzureBlobStorageResource parent ) : Resource ( name ) ,
16
19
IResourceWithConnectionString ,
17
20
IResourceWithParent < AzureBlobStorageResource > ,
18
21
IResourceWithAzureFunctionsConfig
19
22
{
23
+
24
+ /// <summary>
25
+ /// Gets the blob container name.
26
+ /// </summary>
27
+ public string BlobContainerName { get ; } = ThrowIfNullOrEmpty ( blobContainerName ) ;
28
+
20
29
/// <summary>
21
30
/// Gets the connection string template for the manifest for the Azure Blob Storage container resource.
22
31
/// </summary>
@@ -25,7 +34,7 @@ public class AzureBlobStorageContainerResource(string name, AzureBlobStorageReso
25
34
/// <summary>
26
35
/// Gets the parent <see cref="AzureBlobStorageResource"/> of this <see cref="AzureBlobStorageContainerResource"/>.
27
36
/// </summary>
28
- public AzureBlobStorageResource Parent => blobStorage ?? throw new ArgumentNullException ( nameof ( blobStorage ) ) ;
37
+ public AzureBlobStorageResource Parent => parent ?? throw new ArgumentNullException ( nameof ( parent ) ) ;
29
38
30
39
internal void ApplyAzureFunctionsConfiguration ( IDictionary < string , object > target , string connectionName )
31
40
=> Parent . ApplyAzureFunctionsConfiguration ( target , connectionName , Name ) ;
@@ -36,16 +45,20 @@ internal void ApplyAzureFunctionsConfiguration(IDictionary<string, object> targe
36
45
/// <returns>A <see cref="global::Azure.Provisioning.Storage.BlobContainer"/> instance.</returns>
37
46
internal global ::Azure . Provisioning . Storage . BlobContainer ToProvisioningEntity ( )
38
47
{
39
- global ::Azure . Provisioning . Storage . BlobContainer blobContainer = new ( Infrastructure . NormalizeBicepIdentifier ( Name ) ) ;
40
-
41
- if ( Name is not null )
48
+ global ::Azure . Provisioning . Storage . BlobContainer blobContainer = new ( Infrastructure . NormalizeBicepIdentifier ( Name ) )
42
49
{
43
- blobContainer . Name = Name ;
44
- }
50
+ Name = BlobContainerName
51
+ } ;
45
52
46
53
return blobContainer ;
47
54
}
48
55
56
+ private static string ThrowIfNullOrEmpty ( [ NotNull ] string ? argument , [ CallerArgumentExpression ( nameof ( argument ) ) ] string ? paramName = null )
57
+ {
58
+ ArgumentException . ThrowIfNullOrEmpty ( argument , paramName ) ;
59
+ return argument ;
60
+ }
61
+
49
62
void IResourceWithAzureFunctionsConfig . ApplyAzureFunctionsConfiguration ( IDictionary < string , object > target , string connectionName )
50
63
=> ApplyAzureFunctionsConfiguration ( target , connectionName ) ;
51
64
}
0 commit comments