ASP.NET Core???????5??????????????????
???????????? ???????[ 2016/6/17 17:13:28 ] ????????ASP ???ù???
?????????????App.config??Web.config??????XML????????????????ASP.NET Core??????????μ???????????????????????????????????????????????????????????в??????????????????????????????????????????????????????????????????????????????????????XML??JSON??INI????????Щ????????????????????????????????????????????????????ConfigurationProvider???????????????????????????????????????????????????????????????????????ConfigurationProvider??
??????
????MemoryConfigurationProvider
????EnvironmentVariablesConfigurationProvider
????CommandLineConfigurationProvider
????JsonConfigurationProvider
????XmlConfiguationProvider
????IniConfigurationProvider
?????????ConfigurationProvider
???????MemoryConfigurationProvider
??????????μ?2??????????????????????ConfigurationProvider?????????????????????????????????????????????????????????????????????е?ConfigurationProvider?????У?MemoryConfigurationProvider??????????????????????????????????????????????κε???????
????MemoryConfigurationProvider??????“Microsoft.Extensions.Configuration.Memory”???????????????????????????????????????ConfigurationProvider??MemoryConfigurationProvider???????IEnumerable<KeyValuePair<string?? string>>?????????????????????????????????á?????????????????????MemoryConfigurationProvider??????????????????????????????????????Add???????????????
????1: public class MemoryConfigurationProvider : ConfigurationProvider?? IEnumerable<KeyValuePair<string?? string>>
????2: {
????3: public MemoryConfigurationProvider();
????4: public MemoryConfigurationProvider(IEnumerable<KeyValuePair<string?? string>> initialData);
????5:
????6: public void Add(string key?? string value);
????7: public IEnumerator<KeyValuePair<string?? string>> GetEnumerator();
????8: }
??????????????????????MemoryConfigurationProvider???????ConfigurationBuilder??????????????????????????????????????????ConfigurationBuilder??Add??????????????????????????????AddInMemoryCollection??
????1: public static class MemoryConfigurationExtensions
????2: {
????3: public static IConfigurationBuilder AddInMemoryCollection(this IConfigurationBuilder configurationBuilder);
????4: public static IConfigurationBuilder AddInMemoryCollection(this IConfigurationBuilder configurationBuilder?? IEnumerable<KeyValuePair<string?? string>> initialData);
????5: }
????????EnvironmentVariablesConfigurationProvider
??????????壬???????????????????л???????????????????????????????????????????????????????????????????????????????????????????????????????????????????????У???·??????“HKEY_LOCAL_MACHINESYSTEMControlSet001ControlSession ManagerEnvironment”??“HKEY_CURRENT_USEREnvironment ”??
??????????????????????????????????Environment????????????????????????t??????GetEnvironmentVariable????????????????????????????????GetEnvironmentVariables??????????????е??????????EnvironmentVariableTarget?????????????????????????????????洢λ?á?????????GetEnvironmentVariable????GetEnvironmentVariables??????????????target??????????????????EnvironmentVariableTarget.Process????????????????????л??????????????????????????????????????????????б??
1: public static class Environment
2: {
3: public static string GetEnvironmentVariable(string variable);
4: public static string GetEnvironmentVariable(string variable?? EnvironmentVariableTarget target);
5: public static IDictionary GetEnvironmentVariables();
6: public static IDictionary GetEnvironmentVariables(EnvironmentVariableTarget target);
7:
8: public static void SetEnvironmentVariable(string variable?? string value);
9: public static void SetEnvironmentVariable(string variable?? string value?? EnvironmentVariableTarget target);
10: }
11:
12: public enum EnvironmentVariableTarget
13: {
14: Process??
15: User??
16: Machine
17: }
?????????????????????????????SetEnvironmentVariable??????????????????????target???????????????EnvironmentVariableTarget.Process?????????????????????????????????????????????????????value?????????Null?????????????ɡ?
????????EnvironmentVariablesConfigurationProvider???????????????????????????????????????“Microsoft.Extensions.Configuration.EnvironmentVariables”?????У????????????????????NuGet???????????????????????????EnvironmentVariablesConfigurationProvider???????????????????????????????ι?????????ζ?????????????е?????????????????????????????????????????prefix???????????????????????????EnvironmentVariablesConfigurationProvider????ζ?????????????????????????????????
????1: public class EnvironmentVariablesConfigurationProvider : ConfigurationProvider
????2: {
????3: public EnvironmentVariablesConfigurationProvider();
????4: public EnvironmentVariablesConfigurationProvider(string prefix);
????5: public override void Load();
????6: }
??????????????????????????????????????Key??Value?????????????????????EnvironmentVariablesConfigurationProvider????????н???????????Load?????????????????????????????????????????????????????м??ɡ????????????????????????????EnvironmentVariablesConfigurationProvider????????????????????????????????????????????????????????????????????????????????????Key?????????????????????λ???????????EnvironmentVariablesConfigurationProvider??????????
1: public class EnvironmentVariablesConfigurationProvider : ConfigurationProvider
2: {
3: private readonly string prefix;
4:
5: public EnvironmentVariablesConfigurationProvider(string prefix = null)
6: {
7: this.prefix = prefix ?? string.Empty;
8: }
9:
10: public override void Load()
11: {
12: var dictionary = Environment.GetEnvironmentVariables()
13: .Cast<DictionaryEntry>()
14: .Where(it => it.Key.ToString().StartsWith(prefix?? StringComparison.OrdinalIgnoreCase))
15: .ToDictionary(it => it.Key.ToString().Substring(prefix.Length)?? it => it.Value.ToString());
16: this.Data = new Dictionary<string?? string>(dictionary?? StringComparer.OrdinalIgnoreCase);
17: }
18: }
??????
???·???
??????????????????
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