Skip to content

Conversation

@guardrex
Copy link
Collaborator

@guardrex guardrex commented Nov 17, 2025

Fixes #36297

Ilona, do you have a few minutes to review this one? If not, I can ping someone else.

The idea here comes down to pitching (and making our) cascading param access modifiers private for the stated reason that I'm adding to the section on cascading params, namely that ...

The private access modifier is recommended for cascading parameters because the parameter should be scoped for use only within the component's class in most cases. When subclassing is required, use the protected access modifier.

That seems correct reasoning given what I've read from the PU. I've already updated a handful of sample cases where private made the most sense on dotnet/blazor-samples#632, and this PR takes care of examples across the Blazor node. Many examples already used private, so this is making the other examples consistent.


Internal previews

📄 File 🔗 Preview link
aspnetcore/blazor/components/cascading-values-and-parameters.md aspnetcore/blazor/components/cascading-values-and-parameters
aspnetcore/blazor/components/class-libraries-and-static-server-side-rendering.md aspnetcore/blazor/components/class-libraries-and-static-server-side-rendering
aspnetcore/blazor/components/httpcontext.md aspnetcore/blazor/components/httpcontext
aspnetcore/blazor/fundamentals/handle-errors.md aspnetcore/blazor/fundamentals/handle-errors
aspnetcore/blazor/fundamentals/routing.md aspnetcore/blazor/fundamentals/routing
aspnetcore/blazor/globalization-localization.md aspnetcore/blazor/globalization-localization
aspnetcore/blazor/hybrid/root-component-parameters.md aspnetcore/blazor/hybrid/root-component-parameters
aspnetcore/blazor/security/content-security-policy.md aspnetcore/blazor/security/content-security-policy

@guardrex guardrex self-assigned this Nov 17, 2025
@guardrex guardrex requested a review from Copilot November 17, 2025 14:45
Copilot finished reviewing on behalf of guardrex November 17, 2025 14:47
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR standardizes cascading parameter access modifiers to private across Blazor documentation and adds best practice guidance explaining this recommendation. The change aligns with the principle that cascading parameters should be scoped for use only within the component's class in most cases, with protected reserved for scenarios requiring subclassing.

Key Changes

  • Added documentation guidance recommending private access modifiers for cascading parameters with explanation of when to use protected
  • Updated all cascading parameter examples from public or protected to private for consistency across multiple documentation files
  • Changes complement sample code updates already completed in the blazor-samples repository (PR #632)

Reviewed Changes

Copilot reviewed 8 out of 8 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
aspnetcore/blazor/components/cascading-values-and-parameters.md Added new guidance paragraph recommending private access modifier for cascading parameters and updated examples from public to private
aspnetcore/blazor/components/httpcontext.md Changed HttpContext cascading parameter from public to private
aspnetcore/blazor/components/class-libraries-and-static-server-side-rendering.md Changed Context cascading parameter from public to private
aspnetcore/blazor/fundamentals/handle-errors.md Changed ProcessError cascading parameter from public to private in multiple code examples
aspnetcore/blazor/fundamentals/routing.md Changed HttpContext cascading parameter from public to private
aspnetcore/blazor/globalization-localization.md Changed HttpContext cascading parameter from public to private in two separate examples
aspnetcore/blazor/hybrid/root-component-parameters.md Changed KeypadViewModel cascading parameter from protected to private
aspnetcore/blazor/security/content-security-policy.md Changed HttpContext cascading parameter from public to private

@guardrex guardrex requested a review from ilonatommy November 17, 2025 14:49
Copy link
Member

@ilonatommy ilonatommy left a comment

Choose a reason for hiding this comment

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

Based on this comment:
https://github.com/dotnet/aspnetcore/blob/913ff28b8e834b51ded284118accebdaf85697a9/src/Components/Components/src/Reflection/ComponentProperties.cs#L68

I draw a conclusion that the Cascading parameter are indeed not intended to be set from outside the component via its public API. Implicit ancestor access is fine.

@ilonatommy
Copy link
Member

That seems correct reasoning given what I've read from the PU.

What's PU?

@guardrex
Copy link
Collaborator Author

"Product Unit" ... I'm probably the only one using "PU" in conversations, and I probably should stop because few know what I mean. 🙈😄

@guardrex guardrex merged commit d51fa0e into main Nov 20, 2025
4 checks passed
@guardrex guardrex deleted the guardrex/blazor-cascading-params branch November 20, 2025 11:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Clarify cascading params access modifiers

3 participants