Allow configuration binder to bind single elements to array #58060
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.
Backport approved by tactics offline for 6.0.
PR Content
1st PR: #57204
2nd PR: #57872 (applies leftover PR feedback from original)
Customer Impact
When trying to bind from an XML configuration provider, we now can allow to bind single elements to array rather than leaving them as null:
This however would be breaking for other providers (like JSON configuration provider) where this is not expected.
So for example, when binding to:
Even if we change the below JSON:
so that tvshows is an object with a single metadata:
would still bind properly even though json is not specifying an array.
Testing
Using the test that is part of the linked PRs.
Risk
Low – Might incur a little bit of perf cost when app context switch is set to true.
If a customer is not interested in this breaking change they can set the introduced app context switch
Microsoft.Extensions.Configuration.BindSingleElementsToArray
to false and get the old behavior back.Regression?
No
More links
Visit dotnet/docs#25779 for more information.