I posted the program.cs code below in Exhibit 1 which creates the host. Note, that I ".UseWindowsService" and I "AddAzureAppConfiguration". The problem is that my build guy says that the install doesn't work if there is no internet access and this is unacceptable. Huh?
I believe I know the answer to this but thought I'd throw it out to the crowd. Is there a way to pull in the AzureAppConfiguration values after the service is up and running. That said, let me partially answer my question by showing Exhibit 2. This does seem to work but I don't know how to tie it back into the Default Builder once it grabs the values.
But then, to go back to the original question/requirement... will this allow the service to start and not fail on install when there is no internet access? Another way of asking is... can the service start up completely having only a base set of configuration values then be updated after it is running?
Exhibit 1:
public static IHostBuilder CreateHostBuilder(string[] args) =>
Host.CreateDefaultBuilder(args)
.UseWindowsService()
.ConfigureWebHostDefaults(webBuilder =>
{
webBuilder.CaptureStartupErrors(true);
webBuilder.UseStartup<Startup>();
webBuilder.ConfigureLogging((hostingContext, logging) =>
{
logging.AddConfiguration(hostingContext.Configuration.GetSection("Logging"));
logging.AddConsole();
logging.AddDebug();
logging.AddEventSourceLogger();
logging.AddNLog();
});
webBuilder.ConfigureKestrel(options =>
{
options.Listen(IPAddress.Loopback, 8080);
});
webBuilder.ConfigureAppConfiguration((context, config) =>
{
var builtConfig = config.Build();
config.AddAzureAppConfiguration(options =>
{
options.Connect(builtConfig[$"AppConfigEndpoint_{appSettings.Environment}"]
.Decrypt(EncryptionHelper.UniqueId))
.Select(KeyFilter.Any, "Deployed")
.Select(KeyFilter.Any, "Upload");
});
});
});
Exhibit 2:
string env = configuration.GetValue<string>($"CurrentEnvironment");
string endPoint = configuration.GetValue<string>($"AppConfigEndpoint_{env}");
IConfigurationBuilder configBuilder = new ConfigurationBuilder();
configBuilder.AddAzureAppConfiguration(options =>
{
options.Connect(endPoint);
options.Select(KeyFilter.Any, "Deployed")
.Select(KeyFilter.Any, "Upload");
});
configuration = configBuilder.Build();