11// Licensed to the .NET Foundation under one or more agreements.
22// The .NET Foundation licenses this file to you under the MIT license.
33
4+ using System . Diagnostics . CodeAnalysis ;
5+ using System . Runtime . CompilerServices ;
46using Aspire . Hosting . ApplicationModel ;
57using Aspire . Hosting . Azure ;
68using Azure . Provisioning ;
@@ -11,12 +13,19 @@ namespace Aspire.Hosting;
1113/// A resource that represents an Azure Blob Storage container.
1214/// </summary>
1315/// <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 ) ,
1619 IResourceWithConnectionString ,
1720 IResourceWithParent < AzureBlobStorageResource > ,
1821 IResourceWithAzureFunctionsConfig
1922{
23+
24+ /// <summary>
25+ /// Gets the blob container name.
26+ /// </summary>
27+ public string BlobContainerName { get ; } = ThrowIfNullOrEmpty ( blobContainerName ) ;
28+
2029 /// <summary>
2130 /// Gets the connection string template for the manifest for the Azure Blob Storage container resource.
2231 /// </summary>
@@ -25,7 +34,7 @@ public class AzureBlobStorageContainerResource(string name, AzureBlobStorageReso
2534 /// <summary>
2635 /// Gets the parent <see cref="AzureBlobStorageResource"/> of this <see cref="AzureBlobStorageContainerResource"/>.
2736 /// </summary>
28- public AzureBlobStorageResource Parent => blobStorage ?? throw new ArgumentNullException ( nameof ( blobStorage ) ) ;
37+ public AzureBlobStorageResource Parent => parent ?? throw new ArgumentNullException ( nameof ( parent ) ) ;
2938
3039 internal void ApplyAzureFunctionsConfiguration ( IDictionary < string , object > target , string connectionName )
3140 => Parent . ApplyAzureFunctionsConfiguration ( target , connectionName , Name ) ;
@@ -36,16 +45,20 @@ internal void ApplyAzureFunctionsConfiguration(IDictionary<string, object> targe
3645 /// <returns>A <see cref="global::Azure.Provisioning.Storage.BlobContainer"/> instance.</returns>
3746 internal global ::Azure . Provisioning . Storage . BlobContainer ToProvisioningEntity ( )
3847 {
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 ) )
4249 {
43- blobContainer . Name = Name ;
44- }
50+ Name = BlobContainerName
51+ } ;
4552
4653 return blobContainer ;
4754 }
4855
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+
4962 void IResourceWithAzureFunctionsConfig . ApplyAzureFunctionsConfiguration ( IDictionary < string , object > target , string connectionName )
5063 => ApplyAzureFunctionsConfiguration ( target , connectionName ) ;
5164}
0 commit comments