Skip to content
This repository has been archived by the owner on May 1, 2021. It is now read-only.

karb0f0s/EnvJson

Repository files navigation

JsonEnvVar

Load JSON-serialized configurations from environment variables

This package has all the goodness in both Microsoft.Extensions.Configuration.EnvironmentVariables (reads environment variables) and Microsoft.Extensions.Configuration.Json (parses variable as JSON stream) from aspnet/Configuration.

As a result you can write

var config = new ConfigurationBuilder()
                .AddJsonEnvironmentVariables("CI_BUILD_SETTINGS")
                .Build();

var testSettings = config.GetSection("Tests").Get<TestSettings>();

How it Works

Check the ASP.NET Core 2.1 app in sample project.

Run it for the first time without providing any extra configuration:

$ dotnet run
info: Sample.Startup[0]
      ["foo:bar"] = baz

And once with APP_SETTINGS environment variable with a JSON-serialized value:

$ APP_SETTINGS='{"foo":{"bar":"quz"}}' dotnet run
info: Sample.Startup[0]
      ["foo:bar"] = quz

This time the value(quz) in our environment variable overrides the default baz.

About

Store JSON configuration inside environment variables

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages