{"id":29890005,"url":"https://github.com/aoxetech/aoxe.extensions.configuration.etcd","last_synced_at":"2025-07-31T22:23:19.143Z","repository":{"id":253716930,"uuid":"844305283","full_name":"AoxeTech/Aoxe.Extensions.Configuration.Etcd","owner":"AoxeTech","description":"Let the etcd as a configuration source.","archived":false,"fork":false,"pushed_at":"2024-11-25T15:14:37.000Z","size":75,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2024-11-25T16:27:08.180Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/AoxeTech.png","metadata":{"files":{"readme":"README-zh_CN.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-08-19T01:17:51.000Z","updated_at":"2024-11-25T15:15:12.000Z","dependencies_parsed_at":"2024-11-18T13:51:29.406Z","dependency_job_id":"df9b84cf-8449-411c-bf07-d62b451357a0","html_url":"https://github.com/AoxeTech/Aoxe.Extensions.Configuration.Etcd","commit_stats":null,"previous_names":["aoxetech/aoxe.extensions.configuration.etcd"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/AoxeTech/Aoxe.Extensions.Configuration.Etcd","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AoxeTech%2FAoxe.Extensions.Configuration.Etcd","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AoxeTech%2FAoxe.Extensions.Configuration.Etcd/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AoxeTech%2FAoxe.Extensions.Configuration.Etcd/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AoxeTech%2FAoxe.Extensions.Configuration.Etcd/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/AoxeTech","download_url":"https://codeload.github.com/AoxeTech/Aoxe.Extensions.Configuration.Etcd/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AoxeTech%2FAoxe.Extensions.Configuration.Etcd/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":268126583,"owners_count":24200290,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-07-31T02:00:08.723Z","response_time":66,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2025-07-31T22:23:15.571Z","updated_at":"2025-07-31T22:23:19.125Z","avatar_url":"https://github.com/AoxeTech.png","language":"C#","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Aoxe.Extensions.Configuration.Etcd\n\n[English](README.md) | 简体中文\n\n---\n\n使用 etcd 作为配置源, 包括不同的数据源及其对应的解析器 (Json / Xml / Ini / Toml / Yaml).\n\n- [Aoxe.Extensions.Configuration](https://github.com/AoxeTech/Aoxe.Extensions.Configuration)\n- [Aoxe.Extensions.Configuration.Consul](https://github.com/AoxeTech/Aoxe.Extensions.Configuration.Consul)\n- [Aoxe.Extensions.Configuration.Etcd](https://github.com/AoxeTech/Aoxe.Extensions.Configuration.Etcd)\n- [Aoxe.Extensions.Configuration.Redis](https://github.com/AoxeTech/Aoxe.Extensions.Configuration.Redis)\n\n## 1. 为什么需要这个项目\n\nMicrosoft.Extensions.Configuration 提供开箱即用的强大配置功能。它支持多种格式（Json / Xml / Ini），涵盖了大多数使用场景。但我认为它仍有一些可以改进的地方。\n\n### 1.1. 解析器是核心功能，但并没有定义为 public，这种设计影响了模块化和重用\n\n每个配置器都基于其流版本，如 JsonConfigurationProvider / JsonStreamConfigurationProvider 和 XmlConfigurationProvider / XmlStreamConfigurationProvider 等。在 stream provider 中，它使用序列化器将结构流解析为 Dictionary\u003cstring，string?\u003e。但在这些官方的 Configuration 中，解析器类或其函数被定义为 internal 或 pravite。\n\n### 1.2. 使用其它序列化器\n\n就像 Microsoft.Extensions.Configuration.Json 基于 System.Text.Json，它是一个很好的软件包，但由于某些原因，有人更喜欢 Newtonsoft.Json 或其他序列化器，而 Microsoft.Extensions.Configuration.NewtonsoftJson 已从 2020 年起被设置为废弃。除了 Json / Xml / Ini 之外，我们现在可能还需要其他配置格式，如 Toml / Yaml 等。\n\n### 1.3. 更多的配置源\n\n随着微服务和云的发展，集中配置将变得越来越重要。微软为我们提供了一些集中配置源，但它们通常基于azure。在云如此强大的情况下，我们更有理由保持云中立，因为有些项目和服务更喜欢私有部署的键值存储。\n\n## 2. 本项目的作用\n\n### 2.1. Flantteners\n\n对于解析器，Aoxe.Extensions.Configuration 抽象了一个名为 Flanttener 的概念，用于将数据流解析并扁平化为 Dictionary\u003cstring, string?\u003e。现在我们有了以下实现：\n\n#### 2.1.1. Aoxe.Extensions.Configuration.Flattener.Ini\n\n基于 Microsoft.Extensions.Configuration.Ini 并具有相同的行为。\n\n#### 2.1.2. Aoxe.Extensions.Configuration.Flattener.IniParser\n\n[ini-parser](https://github.com/rickyah/ini-parser) 是一个兼容.NET、Mono 和 Unity3d（*）的库，用于从 IO 流、文件流和 C# 编写的字符串中读取/写入 INI 数据。\n\n该库还实现了合并操作，既可合并完整的 INI 文件，也可合并部分文件，甚至只合并文件中包含的键的子集。\n\n(*) 该库是 100% .NET 代码，不依赖于 Windows API 调用，因此具有可移植性。\n\n#### 2.1.3. Aoxe.Extensions.Configuration.Flattener.Json\n\n基于 Microsoft.Extensions.Configuration.Json 并具有相同的行为。\n\n#### 2.1.4. Aoxe.Extensions.Configuration.Flattener.NewtonsoftJson\n\n[Newtonsoft.Json](https://github.com/JamesNK/Newtonsoft.Json) 是.NET 中流行的高性能 JSON 框架。有了这个实现，我们就可以通过 JsonSerializerSettings 来实现反序列化。\n\n#### 2.1.5. Aoxe.Extensions.Configuration.Flattener.SharpYaml\n\n[SharpYaml](https://github.com/xoofx/SharpYaml) 是一个.NET 库，为.NET 对象提供 YAML 解析器和序列化引擎，与 CoreCLR 兼容。\n\n#### 2.1.6. Aoxe.Extensions.Configuration.Flattener.Tomlet\n\n[Tomlet](https://github.com/SamboyCoding/Tomlet) 是一个零依赖、基于模型的 TOML De/Serializer for .NET。\n\n#### 2.1.7. Aoxe.Extensions.Configuration.Flattener.Tomlyn\n\n[Tomlyn](https://github.com/xoofx/Tomlyn) 是一个适用于.NET Framework和.NET Core的TOML解析器、验证器和创作库。\n\n#### 2.1.8. Aoxe.Extensions.Configuration.Flattener.Xml\n\n基于 Microsoft.Extensions.Configuration.Xml 并具有相同的行为。\n\n#### 2.1.9. Aoxe.Extensions.Configuration.Flattener.YamlDotNet\n\n[YamlDotNet](https://github.com/aaubry/YamlDotNet) 是一个用于 YAML 的 .NET 库。YamlDotNet 提供 YAML 的低级解析和发射，以及类似于 XmlDocument 的高级对象模型。该库还包含一个序列化库，允许从 YAML 流中读写对象。\n\n### 2.2. 更多的配置源\n\n除了配置文件，现代服务越来越依赖于集中配置。为此，有以下这些配置源：\n\n#### 2.2.1. [Aoxe.Extensions.Configuration](https://github.com/AoxeTech/Aoxe.Extensions.Configuration)\n\n因为 Flantten 的抽象, Aoxe.Extensions.Configuration 支持不同的配置文件，如 Json、Xml、Ini、Toml 和 Yaml。\n\n#### 2.2.2. [Aoxe.Extensions.Configuration.Consul](https://github.com/AoxeTech/Aoxe.Extensions.Configuration.Consul)\n\n[Consul](https://www.consul.io/) 是一个服务网络解决方案，它提供了一个具有服务发现、配置和分段功能的全功能控制平面。它的设计目的是在分布式基础设施上轻松管理和保障服务间通信。\n\n#### 2.2.3. [Aoxe.Extensions.Configuration.Etcd](https://github.com/AoxeTech/Aoxe.Extensions.Configuration.Etcd)\n\n[Etcd](https://etcd.io/) 是一种分布式键值存储，为跨机器集群存储数据提供了一种可靠的方式。它用于存储配置数据、元数据和其他需要由分布式系统访问的关键信息。\n\n#### 2.2.4. [Aoxe.Extensions.Configuration.Redis](https://github.com/AoxeTech/Aoxe.Extensions.Configuration.Redis)\n\n[Redis（远程字典服务器）](https://redis.io/) 是一种开源的内存数据结构存储，可用作数据库、缓存和消息代理。它支持各种数据结构，如字符串、哈希值、列表、集合、排序集合、位图、HyperLogLogs 和地理空间索引。\n\n## 3. 如何使用\n\n以一个 json 格式的配置为例, 我们现在有一个以 \"test-json\" 为 key 的配置内容如下:\n\n```json\n{\n  \"stringKey\": \"stringValue\",\n  \"numberKey\": 123,\n  \"booleanKey\": true,\n  \"nullKey\": null,\n  \"nestedObject\": {\n    \"nestedStringKey\": \"nestedStringValue\",\n    \"nestedNumberKey\": 456,\n    \"nestedBooleanKey\": false,\n    \"nestedNullKey\": null\n  },\n  \"arrayKey\": [\n    \"arrayStringValue\",\n    789,\n    false,\n    null,\n    {\n      \"arrayNestedObjectKey\": \"arrayNestedObjectValue\"\n    }\n  ]\n}\n```\n\n然后我们通过 nuget 安装对应的包.\n\n```shell\nPM\u003e Install-Package Aoxe.Extensions.Configuration.Etcd.Json\n```\n\n现在我们可以通过这种方式读取 etcd 上的 json 配置信息:\n\n```csharp\nvar configBuilder = new ConfigurationBuilder().AddEtcdJson(\n    new EtcdClientOptions(\"https://127.0.0.1\")\n    {\n        ConfigureChannelOptions = options =\u003e\n            options.Credentials = ChannelCredentials.Insecure\n    },\n    \"/test-json\"\n);\nvar configuration = configBuilder.Build();\nvar value = configuration[\"nestedObject:nestedStringKey\"]; // the value is \"nestedStringValue\"\n```\n\nThank`s for [JetBrains](https://www.jetbrains.com/) for the great support in providing assistance and user-friendly environment for my open source projects.\n\n[![JetBrains](https://resources.jetbrains.com/storage/products/company/brand/logos/jb_beam.svg?_gl=1*f25lxa*_ga*MzI3ODk2MjY0LjE2NzA0NjY4MDQ.*_ga_9J976DJZ68*MTY4OTY4NzY5OS4zNC4xLjE2ODk2ODgwMDAuNTMuMC4w)](https://www.jetbrains.com/community/opensource/#support)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Faoxetech%2Faoxe.extensions.configuration.etcd","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Faoxetech%2Faoxe.extensions.configuration.etcd","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Faoxetech%2Faoxe.extensions.configuration.etcd/lists"}