Add configurable VariableNameTransformation to EnvironmentVariables config#127503
Merged
Conversation
…onfig (dotnet#125137) Adds: - AddEnvironmentVariables(prefix, variableNameTransformation) overload on IConfigurationBuilder. - EnvironmentVariablesConfigurationSource.VariableNameTransformation: a settable property that, when non-null, replaces the default transformation behavior. - EnvironmentVariablesConfigurationSource.DefaultTransformation: the existing default that replaces __ with the configuration key delimiter (:). - EnvironmentVariablesConfigurationSource.ColonAndDotTransformation: replaces ___ with . and __ with :, allowing dots in configuration keys without the override-by-environment ergonomics being limited to colons. ColonAndDotTransformation is implemented with ValueStringBuilder on .NET and StringBuilder on .NET Framework. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Contributor
|
Tagging subscribers to this area: @dotnet/area-extensions-configuration |
svick
commented
Apr 28, 2026
tarekgh
reviewed
Apr 28, 2026
tarekgh
reviewed
Apr 28, 2026
tarekgh
reviewed
Apr 28, 2026
tarekgh
reviewed
May 15, 2026
tarekgh
approved these changes
May 15, 2026
rosebyte
approved these changes
May 18, 2026
Member
rosebyte
left a comment
There was a problem hiding this comment.
LGTM, I left couple suggestions, none of them blocking.
mrek-msft
approved these changes
May 18, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Implements #125137.
API additions
IConfigurationBuilder.AddEnvironmentVariables(string? prefix, Func<string, string>? variableNameTransformation)overload.EnvironmentVariablesConfigurationSource.VariableNameTransformation-- a settableFunc<string, string>?that, when non-null, completely replaces the default transformation.EnvironmentVariablesConfigurationSource.DefaultTransformation-- the existing default that replaces__with the configuration key delimiter (:).EnvironmentVariablesConfigurationSource.ColonAndDotTransformation-- replaces___with.and__with:, so configuration keys containing dots can be set from environment variables.API shape matches @bartonjs's approval comment on the issue.
Implementation notes
ColonAndDotTransformationusesValueStringBuilder+stackalloc char[256]on .NET,StringBuilderon .NET Framework, kept under a single small#if NETregion. No new package references.Prefixis itself passed through the active transformation before comparison, so it should be specified in pre-transformation form (e.g."Logging__"rather than"Logging:"). Documented in<remarks>on thePrefixproperty and the matching overloads.Tests
13 new tests in
EnvironmentVariablesTestcover:[Theory]tables for double/triple/4/5/6 underscores, single-underscore preservation, no-underscore early return).VariableNameTransformationreplacing the default, identity transformation disabling replacement, transformation applied to prefix, source/builder wiring, and a behavioral check thatColonAndDotTransformationis not the default.Note
This PR description and the implementation were drafted with assistance from GitHub Copilot.