microsoft / microsoft/aspire

No API to configure a custom storage account for Durable Functions

Open
#14,849 1 comment 0 reactions 0 assignees View on GitHub
area-integrations azure-functions
Dominant language
C#
Stars
6.3k
Forks
991
Avg merge
2d 15h
Merged PRs (30d)
196

Description

### Is there an existing issue for this?

- [x] I have searched the existing issues

### Is your feature request related to a problem? Please describe the problem.

Azure Durable Functions supports configuring a [custom storage account](https://learn.microsoft.com/en-us/azure/azure-functions/durable/durable-functions-storage-providers#azure-storage) separate from the host storage account (`AzureWebJobsStorage`). This is a common practice in production -- it isolates Durable Task Framework state from the Functions host internals, allows independent scaling and access control, and is recommended by the [Durable Functions performance guidelines](https://learn.microsoft.com/en-us/azure/azure-functions/durable/durable-functions-perf-and-scale).

The custom storage account is configured in `host.json` via the `connectionStringName` property on the storage provider:

```json
{
"extensions": {
"durableTask": {
"hubName": "%DurableTaskHub%",
"storageProvider": {
"connectionStringName": "ConnectionStrings:DurableStorageAccount"
}
}
}
}
```

The Durable Task extension resolves this by looking up the corresponding environment variable/configuration value at runtime. In Aspire, there is currently no public API to set this up. `.WithHostStorage(storage)` only configures `AzureWebJobsStorage` for the Functions host, and there's no way to reference a storage resource under a different connection string name on an Azure Functions project.

The only workaround is to cast to the internal `IResourceWithAzureFunctionsConfig` interface and call `ApplyAzureFunctionsConfiguration` manually:

```csharp
var hostStorage = builder.AddAzureStorage("host-storage").RunAsEmulator();
var durableStorage = builder.AddAzureStorage("durable-storage").RunAsEmulator();

var functions = builder.AddAzureFunctionsProject("functions")
.WithHostStorage(hostStorage)
.WithReferenceRelationship(durableStorage)
.WithEnvironment(context =>
{
// Cast to internal interface -- no public API exists for this
((IResourceWithAzureFunctionsConfig)durableStorage.Resource)
.ApplyAzureFunctionsConfiguration(
context.EnvironmentVariables,
"ConnectionStrings:DurableStorageAccount");
});
```

This works, but relies on an internal interface that could break in future versions and is not discoverable.

### Describe the solution you'd like

There should be a first-class API to reference a storage resource on an Azure Functions project under a named connection string. For example:

```csharp
var functions = builder.AddAzureFunctionsProject("functions")
.WithHostStorage(hostStorage)
.WithReference(durableStorage, "DurableStorageAccount");
```

This would produce the correct Azure Functions-formatted environment variables (`ConnectionStrings:DurableStorageAccount__blobServiceUri`, etc.) that the Durable Task storage provider expects.

### Additional context

_No response_

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.