Skip to content

Commit c4e4092

Browse files
authored
Add Functions host support to AzureTableStorageResource (#7961)
1 parent 3b76943 commit c4e4092

File tree

3 files changed

+24
-1
lines changed

3 files changed

+24
-1
lines changed

playground/AzureFunctionsEndToEnd/AzureFunctionsEndToEnd.AppHost/aspire-manifest.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,10 @@
8181
"ASPNETCORE_URLS": "http://\u002B:{funcapp.bindings.http.targetPort}",
8282
"AzureWebJobsStorage__blobServiceUri": "{funcstorage67c6c.outputs.blobEndpoint}",
8383
"AzureWebJobsStorage__queueServiceUri": "{funcstorage67c6c.outputs.queueEndpoint}",
84+
"AzureWebJobsStorage__tableServiceUri": "{funcstorage67c6c.outputs.tableEndpoint}",
8485
"Aspire__Azure__Storage__Blobs__AzureWebJobsStorage__ServiceUri": "{funcstorage67c6c.outputs.blobEndpoint}",
8586
"Aspire__Azure__Storage__Queues__AzureWebJobsStorage__ServiceUri": "{funcstorage67c6c.outputs.queueEndpoint}",
87+
"Aspire__Azure__Storage__Tables__AzureWebJobsStorage__ServiceUri": "{funcstorage67c6c.outputs.tableEndpoint}",
8688
"myhub__fullyQualifiedNamespace": "{eventhubs.outputs.eventHubsEndpoint}",
8789
"Aspire__Azure__Messaging__EventHubs__EventHubProducerClient__myhub__FullyQualifiedNamespace": "{eventhubs.outputs.eventHubsEndpoint}",
8890
"Aspire__Azure__Messaging__EventHubs__EventHubConsumerClient__myhub__FullyQualifiedNamespace": "{eventhubs.outputs.eventHubsEndpoint}",

src/Aspire.Hosting.Azure.Storage/AzureStorageResource.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ public class AzureStorageResource(string name, Action<AzureResourceInfrastructur
1919

2020
internal const string BlobsConnectionKeyPrefix = "Aspire__Azure__Storage__Blobs";
2121
internal const string QueuesConnectionKeyPrefix = "Aspire__Azure__Storage__Queues";
22+
internal const string TablesConnectionKeyPrefix = "Aspire__Azure__Storage__Tables";
2223

2324
/// <summary>
2425
/// Gets the "blobEndpoint" output reference from the bicep template for the Azure Storage resource.
@@ -70,15 +71,18 @@ void IResourceWithAzureFunctionsConfig.ApplyAzureFunctionsConfiguration(IDiction
7071
// Injected to support Aspire client integration for Azure Storage.
7172
target[$"{BlobsConnectionKeyPrefix}__{connectionName}__ConnectionString"] = connectionString;
7273
target[$"{QueuesConnectionKeyPrefix}__{connectionName}__ConnectionString"] = connectionString;
74+
target[$"{TablesConnectionKeyPrefix}__{connectionName}__ConnectionString"] = connectionString;
7375
}
7476
else
7577
{
7678
// Injected to support Azure Functions listener initialization.
7779
target[$"{connectionName}__blobServiceUri"] = BlobEndpoint;
7880
target[$"{connectionName}__queueServiceUri"] = QueueEndpoint;
81+
target[$"{connectionName}__tableServiceUri"] = TableEndpoint;
7982
// Injected to support Aspire client integration for Azure Storage.
8083
target[$"{BlobsConnectionKeyPrefix}__{connectionName}__ServiceUri"] = BlobEndpoint;
8184
target[$"{QueuesConnectionKeyPrefix}__{connectionName}__ServiceUri"] = QueueEndpoint;
85+
target[$"{TablesConnectionKeyPrefix}__{connectionName}__ServiceUri"] = TableEndpoint;
8286
}
8387
}
8488
}

src/Aspire.Hosting.Azure.Storage/AzureTableStorageResource.cs

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ namespace Aspire.Hosting.Azure;
1111
/// <param name="name">The name of the resource.</param>
1212
/// <param name="storage">The <see cref="AzureStorageResource"/> that the resource is stored in.</param>
1313
public class AzureTableStorageResource(string name, AzureStorageResource storage)
14-
: Resource(name), IResourceWithConnectionString, IResourceWithParent<AzureStorageResource>
14+
: Resource(name), IResourceWithConnectionString, IResourceWithParent<AzureStorageResource>, IResourceWithAzureFunctionsConfig
1515
{
1616
/// <summary>
1717
/// Gets the parent AzureStorageResource of this AzureTableStorageResource.
@@ -23,4 +23,21 @@ public class AzureTableStorageResource(string name, AzureStorageResource storage
2323
/// </summary>
2424
public ReferenceExpression ConnectionStringExpression =>
2525
Parent.GetTableConnectionString();
26+
27+
void IResourceWithAzureFunctionsConfig.ApplyAzureFunctionsConfiguration(IDictionary<string, object> target, string connectionName)
28+
{
29+
if (Parent.IsEmulator)
30+
{
31+
var connectionString = Parent.GetEmulatorConnectionString();
32+
target[connectionName] = connectionString;
33+
target[$"{AzureStorageResource.TablesConnectionKeyPrefix}__{connectionName}__ConnectionString"] = connectionString;
34+
}
35+
else
36+
{
37+
// Injected to support Azure Functions listener.
38+
target[$"{connectionName}__tableServiceUri"] = Parent.TableEndpoint;
39+
// Injected to support Aspire client integration for Azure Storage Tables.
40+
target[$"{AzureStorageResource.TablesConnectionKeyPrefix}__{connectionName}__ServiceUri"] = Parent.TableEndpoint; // Updated for consistency
41+
}
42+
}
2643
}

0 commit comments

Comments
 (0)