ASP.NET Core???????2??????????????
???????????? ???????[ 2016/6/2 14:19:09 ] ?????????????????? ???ù???
?????????????????????????????????????????????????????????漰?????????????????????????????????????Configuration????????????????ConfigurationProvider????????“?м???”??ConfigurationBuilder???????????????????????????????????????????????????????????????????б??????????????????????????????????????????
?????????????????
???????????????в????????????????????????????????????????????????????????????????Configuration???????????????????????????????????λ????ν??????t??ж??????????????????????????????????????????????????????????????y????????????????????????????????????????????????????????м?????????????????????
?????????
????????????????Configuration?????????????????????????????????Configuration?????API????????????????????е?Configuration???????????????????????????????????????????????ν??????????????????????????????????????????Configuration????????????????????????洢????????У????????????????????????y?????????????????????????????????????????????????????FormatSettings???????????????t????????????????????
????????
???????ò????????????????????????ú??????????????????????????????????????????????????????????????????????????????????????????????????FormatSettings??????????????????μ??????XML??JSON???????????????á?
????XML:
1: <Format>
2: <DateTime>
3: <LongDatePattern>dddd?? MMMM d?? yyyy</LongDatePattern>
4: <LongTimePattern>h:mm:ss tt</LongTimePattern>
5: <ShortDatePattern>M/d/yyyy</ShortDatePattern>
6: <ShortTimePattern>h:mm tt</ShortTimePattern>
7: </DateTime>
8: <CurrencyDecimal>
9: <Digits>2</Digits>
10: <Symbol>$</Symbol>
11: </CurrencyDecimal>
12: </Format>
????JSON:
1: {
2: "format": {
3: "dateTime": {
4: "longDatePattern" : "dddd?? MMMM d?? yyyy"??
5: "longTimePattern" : "h:mm:ss tt"??
6: "shortDatePattern" : "M/d/yyyy"??
7: "shortTimePattern" : "h:mm tt"
8: }??
9: "currencyDecimal": {
10: "digits": "2"??
11: "symbol": "$"
12: }
13: }
14: }
?????????
????table???????????????????????????????????????????н?????????????????????????????????????????Configuration?????????????????????????????м???????????????????????????????????????????????FormatSettings????????????????y????????±?????????????
?????????
????transfer???????????????????в????????????????Configuration???????????Configuration?????????????????????????????????????????????????????????????????????????????????????????У???????????????????????????ConfigurationProvider??????????????????????????????????????????????????ConfigurationBuilder????Configuration?????????????????????????????????????
????????Configuration
?????????????????????????????????Configuratin??ConfigurationProvider??ConfigurationBuilder???????????????????????????????????????????????????????????????????????????????Configuration???????2???????Configuration????????????IConfiguration????????y???????“Microsoft.Extensions.Configuration”????????£????δ???????????????漰????????????????????????????????????
????1: public interface IConfiguration
????2: {
????3: IEnumerable<IConfigurationSection> GetChildren();
????4: IConfigurationSection GetSection(string key);
????5: IChangeToken GetReloadToken();
????6:
????7: string this[string key] { get; set; }
????8: }
???????t?????????????????Configuration????????????????????y????????????????????????y????????????????Configuration???????????????y???Configuration?????????в??????????????????????ò??????????????????????????????????Configuration??????????IConfigurationRoot?????????????IConfigurationSection????????????Configuration???????????????IConfiguration????????????????????????????????ConfigurationRoot????????ConfigurationSection???ɡ?
????ConfigurationRoot
??????????????????IConfigurationRoot??????????????????ConfigurationRoot????????????????????IConfigurationRoot????????????????Reload????????????????????????ConfigurationRoot?????????????????????????????????????????????????????????????????????????????
????1: public interface IConfigurationRoot : IConfiguration
????2: {
????3: void Reload();
????4: }
????ConfigurationSection
??????????????????IConfigurationSection??????????????????ConfigurationSection?????ConfigurationSection??????????????????????y??IConfigurationSection????????????????????????Key??????????“???”???y????????????????Path????????????????·??????·????ConfigurationSection??Key??????????e???????????Path??Key????????????????y??????????????е?λ?á?
????1: public interface IConfigurationSection : IConfiguration
????2: {
????3: string Path { get; }
????4: string Key { get; }
????5: string Value { get; set; }
????6: }
????IConfigurationSection??Value?????????y??????????????£???????????????????ConfigurationSection??????????????????????ConfigurationSection?????????????????????????????????????y????????????????Value?????Null???????????????Value???????????????????????д???
???????ConfigurationRoot??ConfigurationSection???л????????????????????????????????IConfiguration?е?????????GetChildren????????????????????y??ConfigurationSection????????????????GetSection??????????Key????????ConfigurationSection??????GetSection??????е???????????????????ConfigurationSection??Path???????????????ConfigurationSection?????·????????????????÷????????????????????????y??·??????????????????????μ???????y??
1: Dictionary<string?? string> source = new Dictionary<string?? string>
2: {
3: ["A:B:C"] = "ABC"
4: };
5: IConfiguration root = new ConfigurationBuilder()
6: .Add(new MemoryConfigurationProvider(source))
7: .Build();
8:
9: IConfigurationSection section1 = root.GetSection("A:B:C");
10: IConfigurationSection section2 = root.GetSection("A:B").GetSection("C");
11: IConfigurationSection section3 = root.GetSection("A").GetSection("B:C");
12:
13: Debug.Assert(section1.Value == section2.Value && section2.Value == section3.Value);
14: Debug.Assert(!ReferenceEquals(section1?? section2) && !ReferenceEquals(section2?? section3));
15: Debug.Assert(null == root.GetSection(Guid.NewGuid().ToString()));
??????????????????????????????????????GetSection????????????·???“Format:DateTime:LongDatePattern”??ConfigurationSection????????δ????????????????????????????????ConfigurationSection???????????????????????????????????????????????仰????????????GetSection???????????????????????????????????·?????????y????????????????μ?ConfigurationSection????
????IConfiguration??????????????????????????????y??Key????????????y??·???????????y????????????????е????????????GetSection?????????μ??????????ConfigurationSection????????????Value???????????????в????????????y????????????Null?????????????
??????
???·???
??????????????????
2023/3/23 14:23:39???д?ò??????????
2023/3/22 16:17:39????????????????????Щ??
2022/6/14 16:14:27??????????????????????????
2021/10/18 15:37:44???????????????
2021/9/17 15:19:29???·???????·
2021/9/14 15:42:25?????????????
2021/5/28 17:25:47??????APP??????????
2021/5/8 17:01:11