Skip to content

Commit

Permalink
Add possibility to overload appsettings.json with environment variables
Browse files Browse the repository at this point in the history
  • Loading branch information
Zcool85 authored and replaysMike committed Aug 5, 2024
1 parent 8f6a659 commit b7d45c9
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
3 changes: 2 additions & 1 deletion Binner/Binner.Web/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,9 @@
WebApplicationBuilder builder;
WebHostServiceConfiguration? config;
try
{
{ // Question : Can we use Config class to reduce the risk of error with BinnerWebHostService.InitializeWebHostAsync ?
builder = WebApplication.CreateBuilder();
builder.Configuration.AddEnvironmentVariables();
config = builder.Configuration.GetSection(nameof(WebHostServiceConfiguration)).Get<WebHostServiceConfiguration>();
if (config == null)
{
Expand Down
3 changes: 2 additions & 1 deletion Binner/Library/Binner.Common/Config.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ public static IConfigurationRoot GetConfiguration(string appSettingsJson, string
throw new FileNotFoundException($"The configuration file named '{filePath}' was not found.");
var builder = new ConfigurationBuilder()
.SetBasePath(path)
.AddJsonFile(appSettingsJson, optional: false, reloadOnChange: true);
.AddJsonFile(appSettingsJson, optional: false, reloadOnChange: true)
.AddEnvironmentVariables();
return builder.Build();
}
}
Expand Down

0 comments on commit b7d45c9

Please sign in to comment.