dotnet / runtime

.NET is a cross-platform runtime for cloud, mobile, desktop, and IoT apps.
https://docs.microsoft.com/dotnet/core/
MIT License
15.17k stars 4.72k forks source link

[API Proposal]: YAML configuration provider #109199

Open stasberkov opened 5 hours ago

stasberkov commented 5 hours ago

Background and motivation

Currently, ASP.NET Core supports configuration providers for JSON, XML, and INI files. However, YAML is a popular configuration format due to its readability and support for complex data structures. Adding a YAML configuration provider would enhance the flexibility and usability of ASP.NET Core applications, especially for developers who prefer or require YAML for their configuration needs.

Benefits:

YAML is widely used in various applications and tools, such as Kubernetes and Ansible, making it a valuable addition to the ASP.NET Core configuration system. By supporting YAML, ASP.NET Core can better align with the preferences and needs of a broader developer community.

API Proposal

builder.Configuration
    .AddYamlFile("appsettings.yaml", optional: false, reloadOnChange: true)
    .AddYamlFile($"appsettings.{builder.Environment.EnvironmentName}.yaml", optional: true, reloadOnChange: true);

API Usage

builder.Configuration
    .AddYamlFile("appsettings.yaml", optional: false, reloadOnChange: true)
    .AddYamlFile($"appsettings.{builder.Environment.EnvironmentName}.yaml", optional: true, reloadOnChange: true);

Alternative Designs

No response

Risks

No response

dotnet-policy-service[bot] commented 5 hours ago

Tagging subscribers to this area: @dotnet/area-extensions-configuration See info in area-owners.md if you want to be subscribed.

am11 commented 4 hours ago

Currently, runtime libraries do not offer built-in support for YAML serialization, which is the prerequisite of this feature request. However, there are community-driven YAML serialization packages like YamlDotNet, which serve as the foundation for various extensions, such as NetEscapades.Configuration.Yaml (https://www.nuget.org/packages/NetEscapades.Configuration.Yaml) and SharpDotYaml.Extensions.Configuration (https://www.nuget.org/packages/SharpDotYaml.Extensions.Configuration). Do these options meet the requirements of your use case?