Roadmap › Custom Controls & Reusable UI Components in .NET — Web Forms to Blazor › Module: Blazor and Desktop Components
Lessons in this course (9)
9. Designing good reusable components
AdvancedMediumLesson 9 of 9
- Small, focused API: few required inputs, sensible defaults, clear names.
- No hidden dependencies on the page: pass data in; raise events out.
- Encode output (XSS): use the framework's encoding (
WriteEncodedText,SetContent, Razor@). - Accessibility: proper labels, keyboard support, ARIA where needed, focus management in dialogs.
- Styling hooks: CSS classes/parameters; CSS isolation in Blazor; themes/skins in Web Forms.
- Performance: avoid heavy ViewState (Web Forms), avoid re-rendering large lists (Blazor
@key,ShouldRender, virtualization), cache data in view components when safe. - Versioning & packaging: shared library/RCL/NuGet with semantic versions; document breaking changes.
- Testing: bUnit (Blazor), unit tests for tag helpers (
TagHelperOutput), UI tests for critical widgets.