简体   繁体   中英

Microsoft.Extensions.Azure register BlobServiceClient when configuration in KeyVault

I am trying to register my Azure client dependencies in program.cs (.Net 6)

In program.cs I have:

builder.Services.AddAzureClients(clientBuilder =>
{
    clientBuilder.AddSecretClient(builder.Configuration.GetSection("akeyvaulturl"));
    clientBuilder.AddBlobServiceClient(HowToGetConfigFromKeyVault).WithName("myblobserviceclient");
});

The only example I can find is: builder.AddBlobServiceClient(Configuration.GetSection("Storage"))

Which is fine if the blob service client is stored in appsettings.json etc. But what if my configuration is stored in KeyVault? I can't see anyway of providing keyvault settings as configuration.

  • I believe, you have to create the ClientInstance for the BlobServiceClient Class that can bring the dependencies for integration of the Azure Key Vault Configuration libraries in .NET Core .

  • Once the configuration builder instance is created/registered, we have to pass the Configuration values stored in respective Service container such as Azure Key Vault:

var appOptions = provider.GetService<IOptions<MyApplicationOptions>>();
return new SecretClient(appOptions.Value.KeyVaultEndpoint, credential, options);
  • Refer to this GitHub article on .NET Core Integration with Azure Client Libraries which shows the Custom Client Factory of Key Vault Configuration to the blobServiceClient object and MS Doc for more information.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM