/// <summary> /// Build the web host /// </summary> /// <param name="kvUrl">URL of the Key Vault</param> /// <param name="authType">MI, CLI, VS</param> /// <returns>Web Host ready to run</returns> private static async Task <IWebHost> BuildHost(string kvUrl, AuthenticationType authType) { // create the Key Vault Client KeyVaultClient kvClient = await KeyVaultHelper.GetKeyVaultClient(kvUrl, authType, Constants.CosmosDatabase).ConfigureAwait(false); if (kvClient == null) { return(null); } // build the config // we need the key vault values for the DAL config = BuildConfig(kvClient, kvUrl); // configure the web host builder IWebHostBuilder builder = WebHost.CreateDefaultBuilder() .UseConfiguration(config) .UseUrls(string.Format(System.Globalization.CultureInfo.InvariantCulture, $"http://*:{Constants.Port}/")) .UseStartup <Startup>() .UseShutdownTimeout(TimeSpan.FromSeconds(Constants.GracefulShutdownTimeout)) .ConfigureServices(services => { // add the data access layer via DI services.AddDal( new Uri(config.GetValue <string>(Constants.CosmosUrl)), config.GetValue <string>(Constants.CosmosKey), config.GetValue <string>(Constants.CosmosDatabase), config.GetValue <string>(Constants.CosmosCollection)); // add the KeyVaultConnection via DI services.AddKeyVaultConnection(kvClient, kvUrl); // add IConfigurationRoot services.AddSingleton <IConfigurationRoot>(config); services.AddKeyRotation(); services.AddResponseCaching(); }); // configure logger based on command line builder.ConfigureLogging(logger => { logger.ClearProviders(); logger.AddConsole(); // if you specify the --log-level option, it will override the appsettings.json options // remove any or all of the code below that you don't want to override if (App.IsLogLevelSet) { logger.AddFilter("Microsoft", AppLogLevel) .AddFilter("System", AppLogLevel) .AddFilter("Default", AppLogLevel) .AddFilter("CSE.Helium", AppLogLevel); } }); // build the host return(builder.Build()); }
/// <summary> /// Build the web host /// </summary> /// <param name="useInMemory">Use in memory DB flag</param> /// <returns>Web Host ready to run</returns> private static IWebHost BuildHost() { // build the config config = BuildConfig(); // configure the web host builder IWebHostBuilder builder = WebHost.CreateDefaultBuilder() .UseConfiguration(config) .UseUrls(string.Format(System.Globalization.CultureInfo.InvariantCulture, $"http://*:{Constants.Port}/")) .UseStartup <Startup>() .UseShutdownTimeout(TimeSpan.FromSeconds(Constants.GracefulShutdownTimeout)) .ConfigureServices(services => { // add the data access layer via DI if (App.Secrets.UseInMemoryDb) { services.AddInMemoryDal(); } else { services.AddDal(new Uri(Secrets.CosmosServer), Secrets.CosmosKey, Secrets.CosmosDatabase, Secrets.CosmosCollection); } // add IConfigurationRoot services.AddSingleton <IConfigurationRoot>(config); services.AddResponseCaching(); }); // configure logger based on command line builder.ConfigureLogging(logger => { logger.ClearProviders(); logger.AddConsole(); // if you specify the --log-level option, it will override the appsettings.json options // remove any or all of the code below that you don't want to override if (App.IsLogLevelSet) { logger.AddFilter("Microsoft", AppLogLevel) .AddFilter("System", AppLogLevel) .AddFilter("Default", AppLogLevel) .AddFilter("CSE.NextGenSymmetricApp", AppLogLevel); } }); // build the host return(builder.Build()); }