Proposal: Enhancing Component Visibility in Blazor
- Dominant language
- C#
- Stars
- 38.4k
- Forks
- 10.9k
- Avg merge
- 2d 5h
- Merged PRs (30d)
- 276
Description
### Is there an existing issue for this?
- [x] I have searched the existing issues
### Is your feature request related to a problem? Please describe the problem.
## Proposal: Enhancing Component Visibility in Blazor
### Description
I am developing a Blazor component library that is consumed by various teams within our organization. During this process, we have identified the need to create internal components that should not be exposed outside of the library.
However, we have encountered a limitation where Razor components in Blazor are required to have public visibility by default. This restriction prevents us from properly encapsulating components that we don't want to make accessible outside the library, which reduces our control over the exposure of our code.
### Problem
- Razor components in Blazor are **public by default** due to inheriting from `ComponentBase`.
- There is **no option** to define internal or restricted components that are only intended to be used within the assembly or library.
- This limitation **exposes unnecessary components** that are not intended to be accessed externally, impacting the modularity and encapsulation of the library.
### Impact
This change would provide more flexibility in how components are designed and structured in Blazor projects. It would help create cleaner, more modular libraries without affecting existing applications, as `public` components would still be fully supported.
I believe it would significantly enhance the development experience for Blazor component libraries.
### Describe the solution you'd like
### Proposal
- Introduce the ability for Razor components to have more restrictive visibility levels, such as `internal` or `protected`.
- This would allow developers to encapsulate components that should remain internal to the library or assembly, improving **modularity** and **code maintainability**.
### Additional context
_No response_
Contributor guide
Assessment
This issue has not been assessed yet.