| File: AzureQueueStorageResource.cs | Web Access |
| Project: src\src\Aspire.Hosting.Azure.Storage\Aspire.Hosting.Azure.Storage.csproj (Aspire.Hosting.Azure.Storage) |
// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. #pragma warning disable ASPIREAZURE003 // Type is for evaluation purposes only and is subject to change or removal in future updates. Suppress this diagnostic to proceed. using Aspire.Hosting.ApplicationModel; namespace Aspire.Hosting.Azure; /// <summary> /// Represents an Azure Queue Storage resource. /// </summary> /// <param name="name">The name of the resource.</param> /// <param name="storage">The <see cref="AzureStorageResource"/> that the resource is stored in.</param> public class AzureQueueStorageResource(string name, AzureStorageResource storage) : Resource(name), IResourceWithConnectionString, IResourceWithParent<AzureStorageResource>, IResourceWithAzureFunctionsConfig, IAzurePrivateEndpointTarget { /// <summary> /// Gets the parent AzureStorageResource of this AzureQueueStorageResource. /// </summary> public AzureStorageResource Parent => storage ?? throw new ArgumentNullException(nameof(storage)); /// <summary> /// Gets the connection URI expression for the queue storage service. /// </summary> /// <remarks> /// Format: <c>https://{host}:{port}</c> for emulator or <c>{queueEndpoint}</c> for Azure. /// </remarks> public ReferenceExpression UriExpression => Parent.QueueUriExpression; /// <summary> /// Gets the connection string template for the manifest for the Azure Queue Storage resource. /// </summary> public ReferenceExpression ConnectionStringExpression => Parent.GetQueueConnectionString(); internal ReferenceExpression GetConnectionString(string? queueName) { if (string.IsNullOrEmpty(queueName)) { return ConnectionStringExpression; } ReferenceExpressionBuilder builder = new(); if (Parent.IsEmulator) { builder.AppendFormatted(ConnectionStringExpression); } else { builder.Append($"Endpoint={ConnectionStringExpression}"); } builder.Append($";QueueName={queueName}"); return builder.Build(); } void IResourceWithAzureFunctionsConfig.ApplyAzureFunctionsConfiguration(IDictionary<string, object> target, string connectionName) { if (Parent.IsEmulator) { var connectionString = Parent.GetEmulatorConnectionString(); target[connectionName] = connectionString; target[$"{AzureStorageResource.QueuesConnectionKeyPrefix}__{connectionName}__ConnectionString"] = connectionString; } else { // Injected to support Azure Functions listener. target[$"{connectionName}__queueServiceUri"] = Parent.QueueEndpoint; // Injected to support Aspire client integration for Azure Storage Queues. target[$"{AzureStorageResource.QueuesConnectionKeyPrefix}__{connectionName}__ServiceUri"] = Parent.QueueEndpoint; } } BicepOutputReference IAzurePrivateEndpointTarget.Id => Parent.Id; IEnumerable<string> IAzurePrivateEndpointTarget.GetPrivateLinkGroupIds() => ["queue"]; string IAzurePrivateEndpointTarget.GetPrivateDnsZoneName() => "privatelink.queue.core.windows.net"; IEnumerable<KeyValuePair<string, ReferenceExpression>> IResourceWithConnectionString.GetConnectionProperties() { yield return new("Uri", UriExpression); if (Parent.IsEmulator) { yield return new("ConnectionString", ConnectionStringExpression); } } }