Aspire.Hosting.Azure.Functions does not use the typical connection string naming convention
Is there an existing issue for this?
- [x] I have searched the existing issues
Describe the bug
When configuring azure functions projects and passing in a reference to blob storage I noticed that the way we access connection strings in the functions application does not work the same was as an API service.
For example, I have this code: builder.AddProject<Projects.ApiService>("apiservice") .WithExternalHttpEndpoints() .WithReference(rabbitMQ) .WithReference(cosmos) .WithReference(blobs) .WaitFor(rabbitMQ) .WaitFor(blobs);
builder.AddAzureFunctionsProject<Projects.Functions>("functions") .WithExternalHttpEndpoints() .WithHostStorage(storage) .WithReference(blobs) .WaitFor(blobs) .WaitFor(storage);
but when access the connection string in the function I get null.
var blobConnectionString = context.Configuration.GetConnectionString("Blobs")!;
My work around was to change the with reference to this: builder.AddAzureFunctionsProject<Projects.PanelInsights_Functions>("functions") .WithExternalHttpEndpoints() .WithHostStorage(storage) .WithReference(blobs, "ConnectionStrings:Blobs") .WaitFor(blobs) .WaitFor(storage);
Expected Behavior
.WithReference(blobs)
paired with: var blobConnectionString = context.Configuration.GetConnectionString("Blobs")!;
should get the value of the connection string
Steps To Reproduce
- Set up an API project and a Functions project
- Connect them using code provided above
- Verify how you access the connection string in both api project and functions project
- Notice that in the function project it returns null
Exceptions (if any)
No response
.NET Version info
9.0.7
Anything else?
No response
That's right, it's because functions projects are a bit strange with respect to configuration. Using the typical naming pattern breaks functons bindings so we use the alternative configuration pattern when applying configuration to functions.
@davidfowl could you please elaborate/point to some docs on what the "alternative configuration pattern" is/means?