diff --git a/src/MicroBatchFramework/BatchHost.cs b/src/MicroBatchFramework/BatchHost.cs index 8aedb96..4cbfbbe 100644 --- a/src/MicroBatchFramework/BatchHost.cs +++ b/src/MicroBatchFramework/BatchHost.cs @@ -6,6 +6,7 @@ using System; using System.IO; using System.Reflection; +using System.Collections.Generic; namespace MicroBatchFramework { @@ -64,24 +65,34 @@ public static IHostBuilder CreateDefaultBuilder(bool useSimpleConosoleLogger, Lo { var builder = new HostBuilder(); - builder.UseContentRoot(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location)); - ConfigureAppConfigurationDefault(builder, hostEnvironmentVariable); + ConfigureHostConfigurationDefault(builder, hostEnvironmentVariable); + ConfigureAppConfigurationDefault(builder); ConfigureLoggingDefault(builder, useSimpleConosoleLogger, minSimpleConsoleLoggerLogLevel); return builder; } - internal static void ConfigureAppConfigurationDefault(IHostBuilder builder, string hostEnvironmentVariable) + internal static void ConfigureHostConfigurationDefault(IHostBuilder builder, string hostEnvironmentVariable) + { + builder.UseContentRoot(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location)); + + builder.ConfigureHostConfiguration(config => + { + config.AddEnvironmentVariables(prefix: "NETCORE_"); + config.AddInMemoryCollection(new[] { new KeyValuePair(HostDefaults.ApplicationKey, Assembly.GetExecutingAssembly().GetName().Name) }); + }); + + if (!string.IsNullOrWhiteSpace(hostEnvironmentVariable)) + { + builder.UseEnvironment(System.Environment.GetEnvironmentVariable(hostEnvironmentVariable) ?? "Production"); + } + } + + internal static void ConfigureAppConfigurationDefault(IHostBuilder builder) { builder.ConfigureAppConfiguration((hostingContext, config) => { var env = hostingContext.HostingEnvironment; - env.ApplicationName = Assembly.GetExecutingAssembly().GetName().Name; - if (string.IsNullOrWhiteSpace(hostEnvironmentVariable)) - { - hostEnvironmentVariable = "NETCORE_ENVIRONMENT"; - } - env.EnvironmentName = System.Environment.GetEnvironmentVariable(hostEnvironmentVariable) ?? "Production"; config.AddJsonFile("appsettings.json", optional: true, reloadOnChange: true); config.AddJsonFile($"appsettings.{env.EnvironmentName}.json", optional: true, reloadOnChange: true);