Giter VIP home page Giter VIP logo

envconfigurationbuildersample's Introduction

Override configration by Environment variables

This is a sample code that overrides the setting with environment variable using Microsoft.Extensions.Configuration. For nested settings, environment variable names (Key) are joined by a colon. A colon can not be set as an environment variable name in bash, but it can be used with Dockerfile. In Microsoft.Extensions.Configuration.EnvironmentVariables, you can also use double underscore (__) instead of a colon (:).

override configration by environment variable

var configuration = new ConfigurationBuilder()
    .SetBasePath(Directory.GetCurrentDirectory())
    .AddJsonFile("settings.json")
    .AddEnvironmentVariables("console0_")
ENV console0_nested:boo1='newvalue2'
ENV console0_nested__boo2='newvalue3'

see: https://github.com/aspnet/Configuration/blob/master/src/Config.EnvironmentVariables/EnvironmentVariablesConfigurationProvider.cs#L65

results

docker-compose up --build

... snip ...

console02_1  | dump configuration
console02_1  | nested=
console02_1  | nested:boo2=newvalue3
console02_1  | nested:boo1=newvalue2
console02_1  | foo=bar
console02_console02_1 exited with code 0

see

MEMO Create Projects

dotnet new console -o console02
cd console02
dotnet add package Microsoft.Extensions.Configuration
dotnet add package Microsoft.Extensions.Configuration.EnvironmentVariables
dotnet add package Microsoft.Extensions.Configuration.Json
dotnet new sln
dotnet sln add ./console02.csproj
git init .
devenv ./console02.sln

envconfigurationbuildersample's People

Contributors

takekazuomi avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.