-
Notifications
You must be signed in to change notification settings - Fork 25.1k
Access modifiers for cascading params #36362
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
There was a problem hiding this 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
privateaccess modifiers for cascading parameters with explanation of when to useprotected - Updated all cascading parameter examples from
publicorprotectedtoprivatefor 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 |
aspnetcore/blazor/components/cascading-values-and-parameters.md
Outdated
Show resolved
Hide resolved
Co-authored-by: Copilot <[email protected]>
ilonatommy
left a comment
There was a problem hiding this 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.
What's PU? |
|
"Product Unit" ... I'm probably the only one using "PU" in conversations, and I probably should stop because few know what I mean. 🙈😄 |
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
privatefor the stated reason that I'm adding to the section on cascading params, namely that ...That seems correct reasoning given what I've read from the PU. I've already updated a handful of sample cases where
privatemade the most sense on dotnet/blazor-samples#632, and this PR takes care of examples across the Blazor node. Many examples already usedprivate, so this is making the other examples consistent.Internal previews