|
6 | 6 | using System; |
7 | 7 | using System.IO; |
8 | 8 | using System.Reflection; |
| 9 | +using System.Collections.Generic; |
9 | 10 |
|
10 | 11 | namespace MicroBatchFramework |
11 | 12 | { |
@@ -64,24 +65,34 @@ public static IHostBuilder CreateDefaultBuilder(bool useSimpleConosoleLogger, Lo |
64 | 65 | { |
65 | 66 | var builder = new HostBuilder(); |
66 | 67 |
|
67 | | - builder.UseContentRoot(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location)); |
68 | | - ConfigureAppConfigurationDefault(builder, hostEnvironmentVariable); |
| 68 | + ConfigureHostConfigurationDefault(builder, hostEnvironmentVariable); |
| 69 | + ConfigureAppConfigurationDefault(builder); |
69 | 70 | ConfigureLoggingDefault(builder, useSimpleConosoleLogger, minSimpleConsoleLoggerLogLevel); |
70 | 71 |
|
71 | 72 | return builder; |
72 | 73 | } |
73 | 74 |
|
74 | | - internal static void ConfigureAppConfigurationDefault(IHostBuilder builder, string hostEnvironmentVariable) |
| 75 | + internal static void ConfigureHostConfigurationDefault(IHostBuilder builder, string hostEnvironmentVariable) |
| 76 | + { |
| 77 | + builder.UseContentRoot(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location)); |
| 78 | + |
| 79 | + builder.ConfigureHostConfiguration(config => |
| 80 | + { |
| 81 | + config.AddEnvironmentVariables(prefix: "NETCORE_"); |
| 82 | + config.AddInMemoryCollection(new[] { new KeyValuePair<string, string>(HostDefaults.ApplicationKey, Assembly.GetExecutingAssembly().GetName().Name) }); |
| 83 | + }); |
| 84 | + |
| 85 | + if (!string.IsNullOrWhiteSpace(hostEnvironmentVariable)) |
| 86 | + { |
| 87 | + builder.UseEnvironment(System.Environment.GetEnvironmentVariable(hostEnvironmentVariable) ?? "Production"); |
| 88 | + } |
| 89 | + } |
| 90 | + |
| 91 | + internal static void ConfigureAppConfigurationDefault(IHostBuilder builder) |
75 | 92 | { |
76 | 93 | builder.ConfigureAppConfiguration((hostingContext, config) => |
77 | 94 | { |
78 | 95 | var env = hostingContext.HostingEnvironment; |
79 | | - env.ApplicationName = Assembly.GetExecutingAssembly().GetName().Name; |
80 | | - if (string.IsNullOrWhiteSpace(hostEnvironmentVariable)) |
81 | | - { |
82 | | - hostEnvironmentVariable = "NETCORE_ENVIRONMENT"; |
83 | | - } |
84 | | - env.EnvironmentName = System.Environment.GetEnvironmentVariable(hostEnvironmentVariable) ?? "Production"; |
85 | 96 |
|
86 | 97 | config.AddJsonFile("appsettings.json", optional: true, reloadOnChange: true); |
87 | 98 | config.AddJsonFile($"appsettings.{env.EnvironmentName}.json", optional: true, reloadOnChange: true); |
|
0 commit comments