Azure-sdk-for-net: AddBlobServiceClient() with multiple clients

Created on 1 Aug 2019  路  4Comments  路  Source: Azure/azure-sdk-for-net

Imagine an application that copies some data to a main blob storage and to a second backup storage as well.

When using AddBlobServiceClient(), it seems that only one BlobServiceClient can be instancied.

Maybe new additional signatures like

public static IAzureClientBuilder<BlobServiceClient, BlobClientOptions> AddBlobServiceClient<TBuilder, TClient>(this TBuilder builder, .............)
            where TBuilder: IAzureClientFactoryBuilderWithConfiguration<TConfiguration>,
                  TClient: BlobServiceClient

would allow the developer to just create an empty derived class to fix the problem:

public MyClass {
     public MyClass(MainBlobServiceClient main, BackupBlobServiceClient backup) { }
}

@pakrym

Client Storage customer-reported

Most helpful comment

Integration layer supports naming the client registrations so it's

``` C#
builder.AddBlobServiceClient().WithName("MyOtherClient");

public class MyClass {
public MyClass(IAzureClientFactory factory){
var other = factory.CreateClient("MyOtherClient");
}
}
```

All 4 comments

Integration layer supports naming the client registrations so it's

``` C#
builder.AddBlobServiceClient().WithName("MyOtherClient");

public class MyClass {
public MyClass(IAzureClientFactory factory){
var other = factory.CreateClient("MyOtherClient");
}
}
```

In my opinion, I find it less clear/usable for DI or mocking, but this use case is maybe uncommon.
But thank you for the answer!

I've considered your approach but it has some downsides, for example to just create an empty derived class to fix the problem is not completely true, you also have to copy all or some of the constructors that you think would get used.

The main downside to using IAzureClientFactory<>, is that you now require a reference to the Microsoft.Extensions.Azure package in your business logic layer, instead of just Azure.Storage.Blobs. So concepts start to bleed a little. At least for the separation I've been using

Was this page helpful?
0 / 5 - 0 ratings