GithubHelp home page GithubHelp logo

configurationbuilderdemos's Introduction

ConfigurationBuilder Demos

Buy Me a Coffee at ko-fi.com

Binding an array

Binding a JSON Array to an Array Object

Recently, when I set a JSON array in the appsettings.json files in an ASP.NET Core project, the result of the final configuration data surprised me. After some googling, I found that there are already many Stack Overflow questions (1, 2, 3, 4, and 5) and GitHub issues (1, 2, 3, 4, 5, and 6) discussing this interesting behavior of configuration inheritance for arrays. I think it is worth writing a short article to describe the "problem" so that you won't stumble on the same stone.

ASP.NET Core uses configuration providers to read configuration key-value pairs from a variety of sources. If there are some key-value pairs with the same keys, then a configuration provider that is added later will override previous key settings. You can read more about configuration in ASP.NET Core in its official documentation, which has covered tons of use cases in detail.

We usually put some generic configuration data in the appsettings.json file, and put environment-specific configurations in the appsettings.{Environment}.json file and/or in the environment variables. In this way, the system can override the settings based on the runtime environment when the application starts. For example, a connection string set in the appsettings.json file will be used for the development environment if its value is not set in the appsettings.Development.json file. On the other hand, if a connection string is set in the appsettings.Production.json file, then the value in the appsettings.json file will be overridden and the value in the appsettings.Production.json file will be used in the production environment.

I also traced back and found this behavior was first proposed in this GitHub issue.

License

Feel free to use the code in this repository as it is under MIT license.

Buy Me a Coffee at ko-fi.com

configurationbuilderdemos's People

Contributors

changhuixu avatar

Stargazers

Mathias Feitzinger avatar

Watchers

James Cloos avatar  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.