Skip to content

Instantly share code, notes, and snippets.

@maxnorth
Last active January 22, 2020 03:15
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/a68ce5f7567a10fd3960e3ca15028c21 to your computer and use it in GitHub Desktop.
Save maxnorth/a68ce5f7567a10fd3960e3ca15028c21 to your computer and use it in GitHub Desktop.
Using environment type to optionally enable key vault provider
using System;
using Microsoft.AspNetCore;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Configuration.AzureKeyVault;
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) =>
{
var env = context.HostingEnvironment.EnvironmentName.ToLowerInvariant();
if (env != "development")
{
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