ASP. NET CORE 2.0 configuration Management

Source: Internet
Author: User

Simple Configuration Management Example (add memory configuration)
usingMicrosoft.Extensions.Configuration;usingSystem;usingSystem.Collections.Generic;namespaceconsolecore{classProgram {Static voidMain (string[] args) {            varDIC =Newdictionary<string,string>()            {                { "name","Wolf"},                 { " Age"," -"},            }; varBuilder =NewConfigurationbuilder ().            Addinmemorycollection (DIC); varConfiguration =Builder.            Build (); Console.WriteLine ($"name:{configuration["Name"]}"); Console.WriteLine ($"age:{configuration["Age"]}");        Console.ReadLine (); }    }}

JSON file configuration
usingMicrosoft.Extensions.Configuration;usingSystem;usingSystem.Collections.Generic;namespaceconsolecore{classProgram {Static voidMain (string[] args) {            varDIC =Newdictionary<string,string>()            {                { "name","Wolf"},                 { " Age"," -"},            }; varBuilder =NewConfigurationbuilder (). Addinmemorycollection (DIC). Addjsonfile ("Wolf.json"); varConfiguration =Builder.            Build (); //key is the same as the previous overlay, and the configuration format is introducedConsole.WriteLine ($"name:{configuration["Name"]}"); Console.WriteLine ($"age:{configuration["Age"]}"); Console.WriteLine ($"age:{configuration["List0: Name"]}"); Console.WriteLine ($"age:{configuration["List0: Age"]}"); Console.WriteLine ($"age:{configuration["List1: Name"]}"); Console.WriteLine ($"age:{configuration["List1: Age"]}");        Console.ReadLine (); }    }}
{  "name": "Wolf1",  "age": +,  "list":[    {      "name": "Wolf2" ,      " Age ": +    },    {      " name ":" Wolf3 ",      " age ": Notoginseng    }  ]}

Bind read configuration to C # instance
usingConsolecore;usingMicrosoft.Extensions.Configuration;usingSystem;usingSystem.Collections.Generic;namespaceconsolecore{classProgram {Static voidMain (string[] args) {            varDIC =Newdictionary<string,string>()            {                { "name","Wolf"},                 { " Age"," -"},            }; varBuilder =NewConfigurationbuilder (). Addinmemorycollection (DIC). Addjsonfile ("Wolf.json"); varConfiguration =Builder.            Build (); varAAA =NewAAA (); Configuration.            Bind (AAA); Console.WriteLine ($"Name:{aaa.list[0].name}"); Console.WriteLine ($"Age:{aaa.list[0].age}");        Console.ReadLine (); }    }     Public classAA { Public stringName {Get;Set; }  Public stringAge {Get;Set; } }     Public classAAA { Public stringName {Get;Set; }  Public stringAge {Get;Set; }  PublicList<aa> List {Get;Set; } }}

Using the options within core MVC

Configuring Hot Updates

Dependency Injection options in views

ASP. NET CORE 2.0 configuration Management

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.