Aore.ConfigManager 1.8.9

dotnet add package Aore.ConfigManager --version 1.8.9
                    
NuGet\Install-Package Aore.ConfigManager -Version 1.8.9
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Aore.ConfigManager" Version="1.8.9" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Aore.ConfigManager" Version="1.8.9" />
                    
Directory.Packages.props
<PackageReference Include="Aore.ConfigManager" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Aore.ConfigManager --version 1.8.9
                    
#r "nuget: Aore.ConfigManager, 1.8.9"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package Aore.ConfigManager@1.8.9
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Aore.ConfigManager&version=1.8.9
                    
Install as a Cake Addin
#tool nuget:?package=Aore.ConfigManager&version=1.8.9
                    
Install as a Cake Tool

Aore.ConfigManager — .NET SDK

Static Badge license

[English Version]

📈 一个基于 .NET Standard 2.0 完全零外部依赖的通用配置读取器工具库组件,助力系统和应用取得成功。我将继续保持更新,并正在深度融合更多场景应用👐

使用 Aore.ConfigManager,您可以方便快速将现有项目或新项目实现配置读取支持。

目前 Aore.ConfigManager 支持 .NET Standard 2.0 等多种框架,同时兼容所有 MVC、Razor、WebApi、Console(命令行)、桌面应用(.exe)和后台服务等环境,和外部框架完全解耦。 适用于需要跨平台兼容性的应用程序开发。

希望有更多的人可以从中受益,理解并传播开源的精神,一同助力中国开源事业!感恩一路上给我们提供帮助的朋友们!

如果你喜欢并希望我们继续优化这个项目,请给我们一个 ★Star :)

✨ 功能特性

  • 跨框架
  • 跨环境
  • 可插拔
  • 支持数据库
  • 高性能:
  • 完全零外部依赖
  • ...

🚀 Aore.ConfigManager 使用示例 :开启你的改造开发之旅!

.NET CLI:
dotnet add package Aore.ConfigManager --version 1.8.9

Nuget包进行搜索下载

🛠 操作使用

Web.config or web.xx.config配置文件

// 实例化并指定类型加载器加载全部配置
AppSettingManager manager = new AppSettingManager()
      .Add(new AppSettingsXmlProvider("Web.config"))
      .Load();
    
Assert.Equal(12, manager.All.Count);
    
// ...

web.config / app.config 读取器(XmlDocument),目前仅支持加载:configuration/appSettings/add下的配置项

appsettings*.json or app.json配置文件

// 实例化并指定类型加载器加载全部配置
AppSettingManager manager = new AppSettingManager()
      .Add(new JsonConfigProvider("appsettings.json"))
      .Load();
    
Assert.Equal(3, manager.All.Count);
    
// ...

手写一个 极简递归下降解析器(仅支持 string/number/bool/null/object/array),满足 appsettings*.json 的 key-value 扁平化需求

DatabaseConfig数据库读取器

// 实例化并指定类型加载器加载全部配置
// 首先项目要提供连接数据的驱动依赖(System.Data.SQLite)
// SQL指定返回两列(第一列为Key,第二列为Value)
AppSettingManager manager = new AppSettingManager()
      .Add(new DatabaseConfigProvider("System.Data.SQLite", "Data Source=AppConfig.db;Version=3;", "SELECT [Key],[Value] FROM config"))
      .Load();
    
Assert.Equal(2, manager.All.Count);
    
// ...

项目要有对应驱动(System.Data.SqlClient / Microsoft.Data.SqlClient / MySql.Data 等)即可,无需编译期引用

获取配置值的方法API

Assert.Equal("localhost", manager["Host"]);
    
Assert.Equal("localhost", manager.All["Host"]);

// Test GetConfig<T>
Assert.Equal("localhost", manager.GetConfig<string>("Host"));
Assert.Equal(443, manager.GetConfig<int>("Port"));

// Test GetConfig(string key, string defaultValue = "")
Assert.Equal("localhost", manager.GetConfig("ERP_URL", "localhost"));

// Test GetTryConfig
string? sERPUrl;
Assert.Equal(false, manager.GetTryConfig("ERP_URL", out sERPUrl));

// Test GetTryConfig DefaultValue
Assert.Equal(true, manager.GetTryConfig("ERP_URL", "loaclhost", out sERPUrl));
Assert.Equal("loaclhost", sERPUrl);
    
// ...

字典类型的配置转换成指定类型

(字典Key ⇒ 对象中的字段)

AppSettingManager manager = new AppSettingManager()
      .Add(new AppSettingsXmlProvider("Web.config"))
      .Load();
    
WebConfigModel model = manager.ConvertTo<WebConfigModel>();
    
Assert.Equal("localhost", model.Host);

// 配置对象
class WebConfigModel
{
  public string? Host { get; set; }
  public int Port { get; set; }
}
    
// ...


// appsetting.json => Object
AppSettingManager manager = new AppSettingManager()
      .Add(new JsonConfigProvider("appsettings.json"))
      .Load();
    
// 如果是Json的配置字段转换成给对象的属性
// 就需要属性对象命名与Json名称的对应关系(json的key是Logging:LogLevel:Default这种类型,其中对象属性为:Logging_LogLevel_Default)
LoggingModel model = manager.ConvertTo<LoggingModel>();

Assert.Equal("Debug", model.Logging_LogLevel_Default);

// 配置对象
class LoggingModel
  {
    public string? Logging_LogLevel_Default { get; set; }
    public string? Logging_LogLevel_System { get; set; }
  }

✋ 贡献代码

如果需要使用或修改此项目的源代码,建议先Fork。也欢迎将您修改的通用版本Pull Request过来。

  1. Fork
  2. 创建您的特性分支 (git checkout -b my-new-feature)
  3. 提交您的改动 (git commit -am 'Added some feature')
  4. 将您的修改记录提交到远程 git 仓库 (git push origin my-new-feature)
  5. 然后到 github 网站的该 git 远程仓库的 my-new-feature 分支下发起 Pull Request (请提交到 Developer 分支,不要直接提交到 master 分支)
Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • .NETStandard 2.0

    • No dependencies.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.8.9 319 8/8/2025

Aore.ConfigManager is a universal configuration reader that is cross framework, cross environment, pluggable, and supports databases component for .NET