Last active
January 22, 2020 03:15
-
-
Save maxnorth/a68ce5f7567a10fd3960e3ca15028c21 to your computer and use it in GitHub Desktop.
Using environment type to optionally enable key vault provider
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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