dotnet / runtime

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

[API Proposal]: YAML configuration provider #109199

Open stasberkov opened 1 month ago

stasberkov commented 1 month 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 1 month ago

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

am11 commented 1 month 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?

stasberkov commented 1 month ago

Yeah, I saw these libs. I would like to minimize dependency on 3rd party libs for core functionality. I believe configuration is a part of application core.

am11 commented 1 month ago

I would like to minimize dependency on 3rd party libs for core functionality.

See this discussion https://github.com/dotnet/runtime/issues/83313#issuecomment-1465282960, generally third party libraries is the way to go when it comes to YAML. https://github.com/dotnet/runtime/issues/83313 is the prerequisite, and other similar proposals before that (which were not accepted).