Skip to content

Commit

Permalink
Fix bug with BlobStorage in local environment not using KeyedService (#…
Browse files Browse the repository at this point in the history
…597)

### Summary & Motivation
With the upgrade to a newer version of .NET, a bug was exposed in the
`PlatformPlatform` code, specifically affecting the avatars blob storage
setup. The issue surfaced because the BlobStorage account was registered
as a normal service rather than a keyed service in the local environment
configuration (when not running in Azure). While this was not a problem
in the previous .NET version, the upgrade made the bug evident. This PR
resolves the issue by registering the BlobStorage account as a keyed
service in the local environment, aligning the behavior with the
intended configuration and fixing the bug in `PlatformPlatform`.

### Checklist

- [x] I have added a Label to the pull-request
- [x] I have added tests, and done manual regression tests
- [x] I have updated the documentation, if necessary
  • Loading branch information
tjementum authored Oct 9, 2024
2 parents 3bbaa87 + 745932b commit 6a11e7f
Showing 1 changed file with 6 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,12 @@ public static IHostApplicationBuilder AddNamedBlobStorages(
else
{
var connectionString = builder.Configuration.GetConnectionString("blob-storage");
builder.Services.AddSingleton(new BlobStorage(new BlobServiceClient(connectionString)));
foreach (var connection in connections)
{
builder.Services.AddKeyedSingleton(connection.ConnectionName,
(_, _) => new BlobStorage(new BlobServiceClient(connectionString))
);
}
}

return builder;
Expand Down

0 comments on commit 6a11e7f

Please sign in to comment.