-
Notifications
You must be signed in to change notification settings - Fork 747
Support for multiple Azurite storage accounts in RunAsEmulator #13266
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
Implements the ability to configure multiple custom storage accounts
for the Azure Storage emulator (Azurite) when using RunAsEmulator.
New public types:
- AzureStorageEmulatorAccount class for defining custom accounts
New extension methods:
- WithAccounts() on AzureStorageEmulatorResource to configure accounts
- WithAccount() on AzureBlobStorageResource to specify which account to use
- WithAccount() on AzureQueueStorageResource to specify which account to use
- WithAccount() on AzureTableStorageResource to specify which account to use
Usage example:
```csharp
var legacyAccount = new AzureStorageEmulatorAccount("legacy");
var newAccount = new AzureStorageEmulatorAccount("newdata");
var storage = builder.AddAzureStorage("storage")
.RunAsEmulator(c => c.WithAccounts(legacyAccount, newAccount));
var legacyTables = storage.AddTables("legacy-tables").WithAccount(legacyAccount);
var newTables = storage.AddTables("new-tables").WithAccount(newAccount);
```
Co-authored-by: davidfowl <[email protected]>
Co-authored-by: davidfowl <[email protected]>
Co-authored-by: davidfowl <[email protected]>
|
@copilot The factory methods don't seem idiomatic but the layering seems good. The account creation is the only atypical API. |
Replace static Create() factory methods with direct constructor usage, making the API more idiomatic per code review feedback. Co-authored-by: davidfowl <[email protected]>
|
@copilot Maybe we can use strings so that accounts aren't objects. var storage = builder.AddAzureStorage("storage")
.RunAsEmulator(c => c.WithAccounts("legacy"));
var legacyTables = storage.AddTables("legacy-tables").WithAccount("legacy");OR var storage = builder.AddAzureStorage("storage")
.RunAsEmulator(c => c.WithAccounts("acc1", "somekey"));
var legacyTables = storage.AddTables("another").WithAccount("acc1"); |
Per reviewer feedback, changed the public API to use simple strings
for account names instead of AzureStorageEmulatorAccount objects.
The new API is cleaner:
- WithAccounts("acc1", "acc2") instead of WithAccounts(account1, account2)
- WithAccount("acc1") instead of WithAccount(account1)
The AzureStorageEmulatorAccount class is now internal and used only
for internal tracking of account details.
Co-authored-by: davidfowl <[email protected]>
Simplified the API to use strings in commit 989935f. The API now looks like: var storage = builder.AddAzureStorage("storage")
.RunAsEmulator(c => c.WithAccounts("legacy", "newdata"));
var legacyTables = storage.AddTables("legacy-tables").WithAccount("legacy");The |
|
@copilot Update the readme to show this feature and link to the original docs for it in azureite |
|
🚀 Dogfood this PR with:
curl -fsSL https://raw.githubusercontent.com/dotnet/aspire/main/eng/scripts/get-aspire-cli-pr.sh | bash -s -- 13266Or
iex "& { $(irm https://raw.githubusercontent.com/dotnet/aspire/main/eng/scripts/get-aspire-cli-pr.ps1) } 13266" |
Added a link to the official Azurite documentation for custom storage accounts and keys in the README. Co-authored-by: davidfowl <[email protected]>
|
@copilot We can remove teh hardcoded values from AzureStorageEmulatorConnectionString now that we have a general AzureStorageEmulatorAccount |
Unfortunately, this duplication is necessary due to the test infrastructure. The test project compiles |
Co-authored-by: davidfowl <[email protected]>
|
Have you thought about using a singleton emulator and only accepting a single account in When it runs it can aggregates all the account values for set the config. var storageA = builder.AddAzureStorage("storage").RunAsEmulator(c => c.WithAccount("A"));
var storageB = builder.AddAzureStorage("storage").RunAsEmulator(c => c.WithAccount("B"));
var legacyTables = storageA.AddTables("legacy-tables");
var newTables = storageB.AddTables("legacy-tables");How does that work though when you deployed on real storage? There won't be isolation anymore. |
Description
Adds support for configuring multiple storage accounts when using
AddAzureStorage().RunAsEmulator(). Azurite supports custom accounts via theAZURITE_ACCOUNTSenvironment variable, enabling isolation between different parts of an application without running multiple emulator containers.For more information on Azurite's custom storage accounts feature, see the Azurite documentation.
New public API:
WithAccounts(params string[] accountNames)- Configures custom accounts on the Azurite emulator (keys are auto-generated)WithAccount(string accountName)- Assigns a specific account to blob, queue, or table resourcesUsage:
Fixes #8931
Checklist
<remarks />and<code />elements on your triple slash comments?doc-ideatemplatebreaking-changetemplatediagnostictemplateOriginal prompt
💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.