I have an application which i would like to make reference to two different storage accounts (SA1 and SA2) which both has a single contaner each "container1" and "container2" respectively. I have the below DI setup for both (Not sure this is correct)
serviceCollection.AddAzureClients(builder =>
{
builder.AddBlobServiceClient("SA1_connectionStr"))
.WithVersion(BlobClientOptions.ServiceVersion.V2019_02_02);
builder.AddBlobServiceClient("SA2_connectionStr"))
.WithVersion(BlobClientOptions.ServiceVersion.V2019_02_02);
});
When i use the "blobContainer" reference (using the code below) it’s only refering the container in the "SA2" storgaeAccount (maybe bcause it was added last in the DI setup)
private readonly BlobServiceClient blobServiceClient;
var blobContainer = blobServiceClient.GetBlobContainerClient(container2);
How do i make reference to storageAccount SA1 and storageAccount SA2 seperately?
2
Answers
You’re going to want to the name the clients in order to differentiate them:
and then you can access them by injecting:
into your constructor and then
and then use those clients to actually interact with the different containers.
You can checkout the official documentation for this here.
alternitive to akseli