关于配置文件的目录:[Asp.net 5] Configuration-新一代的配置文件

本系列文章讲的是asp.net 5(Asp.net VNext)中的配置文件部分,工程下载地址为:https://github.com/aspnet/Configuration

本节讲的是Configuration解决方案中的Microsoft.Framework.Configuration和Microsoft.Framework.Configuration.Abstractions俩个工程。

Abstractions

首先我们看下Configuration.Abstractions这个工程的详情:

[Asp.net 5] Configuration-新一代的配置文件(接口定义与基础实现)

该工程中只定义了三个接口:IConfiguration、IConfigurationBuilder、IConfigurationSource,是完全为了抽象而设计的工程。

我们在依赖注入(DependencyInjection)篇中也接触过名字为“Abstractions”的工程(链接地址:http://www.cnblogs.com/watermoon2/p/4511269.html),也是只包含必须的接口定义,我们可以推测,微软的命名规则是对于XXXX类工程:

  • Microsoft.Framework.XXXX.Abstractions:定义微软XXXX的必须的抽象
  • Microsoft.Framework.XXXX:定义微软的XXXX的基础实现,内部类多实现Microsoft.Framework.XXXX.Abstractions中接口

配置文件中,肯定少不了配置文件类的基础接口定义:IConfiguration;我们知道新的配置文件实现,支持配置文件有多个来源,可以来自xml、可以来自json、也可以既有部分来自xml,又有部分来自json,所以接口中定义了“IConfigurationSource”接口,用于标示配置文件的来源;而IConfigurationBuilder是IConfiguration的构造器。

这个工程代码比较少,下面我就将接口定义罗列如下:

public interface IConfigurationSource
    {
        bool TryGet(string key, out string value);

        void Set(string key, string value);

        void Load();

        IEnumerable<string> ProduceConfigurationSections(
            IEnumerable<string> earlierKeys,
            string prefix,
            string delimiter);
    }
 public interface IConfigurationBuilder
    {
        string BasePath { get; }

        IEnumerable<IConfigurationSource> Sources { get; }

        IConfigurationBuilder Add(IConfigurationSource configurationSource);

        IConfiguration Build();
    }

public interface IConfiguration
    {
        string this[string key] { get; set; }

        string Get(string key);

        bool TryGet(string key, out string value);

        IConfiguration GetConfigurationSection(string key);

        IEnumerable<KeyValuePair<string, IConfiguration>> GetConfigurationSections();

        IEnumerable<KeyValuePair<string, IConfiguration>> GetConfigurationSections(string key);

        void Set(string key, string value);

        void Reload();
    }
接口定义

相关文章:

  • 2021-10-18
  • 2021-11-26
  • 2022-12-23
  • 2022-01-16
  • 2022-01-10
  • 2021-10-19
  • 2022-12-23
  • 2021-08-27
猜你喜欢
  • 2022-03-03
  • 2021-06-07
  • 2021-09-24
  • 2022-12-23
  • 2022-02-13
  • 2022-12-23
  • 2021-11-09
相关资源
相似解决方案