1

I was working on a project which required me to create Keyvault reference in azure AppConfiguration, add/update secrets in KeyVault and to access values in AppConfiguration using Configuration. Currently, I'm using :

-ConfigurationClient to create key Vault reference.

-SecretClient to add/update secrets in KeyVault.

-Configuration build using the builder.AddAzureAppConfiguration().build() to access values in AppConfiguration.(using builder.AddAzureAppConfiguration() is a necessity due to its features).

So, basically 3 connections to azure are made here. Is there any way to decrease the no. of connections? Like, using the ConfigurationBuilder to get a ConfigurationClient and/or SecretClient.

Mehawk
  • 31
  • 3

1 Answers1

0

Since your application is accessing two different resources, App Configuration and Key Vault, a minimum of two connections are needed. This is due to lack of support for shared connections across different services.

Assuming your application is using ConfigureKeyVault to access Key Vault references, the call to AddAzureAppConfiguration().Build() is actually creating two connections - one to App Configuration and the other to Key Vault. In this case, there are a total of 4 connections. You can reduce it to 3 by registering the SecretClient you created to add/update secrets in Key Vault in the AddAzureAppConfiguration method.

SecretClient secretClient = new SecretClient(new Uri("http://my-keyvault-uri"), new DefaultAzureCredential());

builder.AddAzureAppConfiguration(options =>
{
    options.Connect(settings["connection_string"])
            .ConfigureKeyVault(kv => kv.Register(secretClient));
});

At this time, there isn't a supported way to provide an existing instance of ConfigurationClient while setting up the AddAzureAppConfiguration method, but this may be supported in the future.

Abhilash Arora
  • 277
  • 2
  • 4
  • Yup, I'm already using the register method. I was thinking if there was any similar way to pass in configuration client in the builder instead of the configuration string. – Mehawk May 19 '20 at 06:20
  • At this time, there isn't a public method to pass in a configuration client. The only possible way I see is to update the internal property `AzureAppConfigurationOptions.Client` using reflection, but I wouldn't recommend that approach. We will consider adding a public method to provide a custom instance of the client in a future release. – Abhilash Arora May 23 '20 at 01:42
  • Well, Yeah reflection approach won't be the right thing to do I agree, It looks like I would be going fr the normal method. Thanks by the way :) – Mehawk Jun 02 '20 at 08:25