Skip to content

Instantly share code, notes, and snippets.

@maxnorth

maxnorth/Program.cs

Last active Jan 22, 2020
Embed
What would you like to do?
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
You can’t perform that action at this time.