ASP. NET core Source fragrance: Configuration Components

Source: Internet
Author: User

Brief introduction:

  This is a basic component, is a unified configuration model, configuration can be derived from the configuration file (JSON file, XML file, INI file), memory objects, command line parameters, system environment variables or your own extension of the configuration source, The component loads the data for each configuration source in a uniform format (idictionary<string, string> data), providing a calling interface externally.

Furthermore, some configuration sources, such as file configuration sources, can also be reloaded (idictionary<string, string> data) when the data of the configuration source changes, and the programmer can always determine whether a callback has been reloaded or registered, Add business logic when reloading the configuration.

Let us start from a question into the source: different format of the configuration source (such as JSON data) is how to turn into idictionary<string, string> data, hierarchical relationship lost it?

As you can see, the hierarchical relationship uses a colon (:) delimited when converting to a dictionary key, and if the child node is an array, the middle is also delimited with the index of the array item (see: configuration["Wizards:0:name"]), with this separation pattern, Any data source can be converted to idictionary<string, string> object.

Model:

The model of the configuration component consists of the following core objects:

1.ConfigurationBuilder//Programming portal, responsible for collecting configuration source (config file, command line parameters,                                                          Memory objects, etc.) and the configuration source build to be collected (call the build method of each configuration source Configurationsource) into a configuration provider The collection of (Iconfigurationprovider) passes through the Configurationroot object, which completes the process of data load on different data sources.

2.IConfigurationSource//Different configuration sources implement this interface, primarily providing Iconfigurationprovider objects for the build process above.

3.IConfigurationProvider//Where the configuration data load is implemented, and where the data is reloaded and the change notification occurs when the data source changes.

4.ConfigurationRoot//The user directly uses the configuration object, which manages the collection of Iconfigurationprovider objects, and the get and set operations are completed by invoking each Iconfigurationprovider from this object.

5.ConfigurationSection//Configure child Node Action object

SOURCE said things:

1. How does a JSON file become a Dictionary object that provides configuration services for us?

Summarize:

The source code of the configuration component is relatively simple, but the implementation of the function is very powerful. Inside the design ideas and implementation techniques are amazing. ASP. NET core series of the framework source code are like this, the implementation of the technique as Shaolin 72 stunt, every frame is amazing!

Related articles:

    • asp: Starting from Hosting

Original address: http://www.cnblogs.com/shiliyuanma/p/6682437.html

asp: Configuration components (GO)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.