Can AzureClientServiceCollectionExtensions.AddAzureClients
be called multiple times without any problems, i.e. will all clients be appended/added to the same builder, even when spread across multiple method invocations?
For context: I have split up the general setup and configuration for Azure Storage Account and for Azure Service Bus in separate files. From each file I would like to call AddAzureClients
in order to add ServiceBusClient
and BlobServiceClient
respectively.
Short answer, most likely.
Long answer, judging by the implementation in GitHub https://github.com/Azure/azure-sdk-for-net/blob/main/sdk/extensions/Microsoft.Extensions.Azure/src/AzureClientServiceCollectionExtensions.cs multiple calls to the AddAzureClients should be fine. It's implementation makes registration calls for it's required types using the TryAddSingleton method which will only register types if they haven't already been registered. As for whether all the calls to the AddAzureClients will be fine as that method is an extension method on the IServiceCollection type so long as each of your subsequent calls is on the same service collection you should be fine.