Skip to content

Switch ValidateContext.ValidationErrors to IReadOnlyList<string> instead of IEnumerable<string> - #67659

Merged
Youssef1313 merged 3 commits into
mainfrom
dev/ygerges/readonlylist
Jul 8, 2026
Merged

Youssef1313 merged 3 commits into
mainfrom
dev/ygerges/readonlylist

Conversation

@Youssef1313

Copy link
Copy Markdown
Member

Related to #66980

Copilot AI review requested due to automatic review settings July 8, 2026 07:12

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Updates Microsoft.Extensions.Validation.ValidateContext’s ValidationErrors value type from IEnumerable<string> to IReadOnlyList<string> to better reflect the concrete, materialized error collection shape and avoid exposing potentially lazy / multi-enumeration semantics.

Changes:

  • Change ValidateContext.ValidationErrors to IReadOnlyDictionary<string, IReadOnlyList<string>>?.
  • Update internal _validationErrors storage and helper signatures to use IReadOnlyList<string> consistently.

Comment thread src/Validation/src/ValidateContext.cs Resolved
Comment thread src/Validation/src/ValidateContext.cs Resolved
Comment thread src/Validation/src/ValidateContext.cs Resolved
@Youssef1313
Youssef1313 merged commit 7645238 into main Jul 8, 2026
25 checks passed
@Youssef1313
Youssef1313 deleted the dev/ygerges/readonlylist branch July 8, 2026 10:26
@halter73

halter73 commented Jul 8, 2026

Copy link
Copy Markdown
Member

Could we avoid exposing the mutable backing collections here? Even though the public API is IReadOnlyDictionary<string, IReadOnlyList<string>>, the current implementation returns the actual Dictionary and stores actual List<string> values, so a caller can cast back to Dictionary<string, IReadOnlyList<string>> / List<string> and mutate the validation state externally.

Can we use ReadOnlyDictionary for the outer collection and AsReadOnly() lists for the values while keeping the mutable lists private for internal accumulation?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

feature-validation Issues related to model validation in minimal and controller-based APIs

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants