Skip to content

Instantly share code, notes, and snippets.

@maxnorth
Last active January 22, 2020 01:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save maxnorth/d14ec3394aa40693d617d5d4906801b8 to your computer and use it in GitHub Desktop.
Save maxnorth/d14ec3394aa40693d617d5d4906801b8 to your computer and use it in GitHub Desktop.
Adding the Key Vault config provider in Asp.Net Core
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>netcoreapp3.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Configuration.AzureKeyVault" Version="3.0.0" />
</ItemGroup>
</Project>
using Microsoft.AspNetCore;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
namespace Example
{
public class Program
{
public static void Main(string[] args)
{
CreateWebHostBuilder(args).Build().Run();
}
public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
WebHost.CreateDefaultBuilder(args)
.UseStartup<Startup>()
.ConfigureAppConfiguration((context, configBuilder) =>
{
// first we need to build the config object so we can grab the key vault url that
// was passed in another way, such as an environment variable or appsettings.json
var config = configBuilder.Build();
configBuilder.AddAzureKeyVault(config["KeyVaultUrl"]);
});
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment