.claude/skills/blazor-standards/SKILL.md
Use when working with Blazor Server or WebAssembly components, Razor markup, SignalR, render modes, or interactive server patterns. Provides domain-specific rules layered on top of base architectural standards.
npx skillsauth add klod68/littlerae blazor-standardsInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
| Field | Value |
|---|---|
| Name | Blazor Component & Architecture Standards |
| Domain | UI, Web Components, Blazor |
| Level | Feature |
| Tags | blazor, razor, signalr, components, wasm |
Activate this skill when the task involves:
.razor) or code-behind (.razor.cs) filesOnInitializedAsync, OnAfterRenderAsync)These rules layer on top of base architectural standards. On conflict, these win.
<!-- SHARED:rules/blazor.md -->Apply these rules in addition to _base.md for Blazor Server and Blazor WebAssembly projects.
Microsoft.NET.Sdk.Web in the .csproj.App.razor is the HTML entry point: <!DOCTYPE html>, <head> with <HeadOutlet />, <body> with <Routes />, and <script src="_framework/blazor.server.js" /> (Server) or blazor.webassembly.js (WASM).Routes.razor contains the <Router> component with AppAssembly="typeof(App).Assembly" and a DefaultLayout.Program.cs:
builder.Services.AddRazorComponents()
.AddInteractiveServerComponents(); // or .AddInteractiveWebAssemblyComponents()
app.MapRazorComponents<App>()
.AddInteractiveServerRenderMode(); // or .AddInteractiveWebAssemblyRenderMode()
_Imports.razor must include @using static Microsoft.AspNetCore.Components.Web.RenderMode to allow @rendermode InteractiveServer without qualification.@rendermode InteractiveServer (or InteractiveAuto) at the top — static SSR is the default if omitted..sln / .slnx file — this is the most commonly forgotten step when scaffolding..razor (markup) and .razor.cs (code-behind partial class) files.UserCard, OrderSummary, not ShowUser..razor files — markup and binding only..razor.cs partial class, which delegates to injected services.private fields — never public unless bound via [Parameter].MyFeatureState) registered in DI — never in a static class.StateHasChanged() is called only when the runtime cannot detect the change automatically (e.g., async callbacks, timer events).[Parameter] properties are init-only or have private setters — never publicly mutable from outside.EventCallback<T> for child-to-parent communication — never expose parent references to child components.OnInitializedAsync — never in OnParametersSetAsync unless the data depends on a changed parameter.firstRender in OnAfterRenderAsync to avoid redundant calls.CancellationToken from Component.CancellationToken (Blazor 8+) or manage it manually via IDisposable.IMyFeatureApiClient service.IDisposable / IAsyncDisposable must be implemented when the component subscribes to events or holds resources.@page routes; layout components never declare routes.NavigationManager.NavigateTo — never by manipulating the URL string directly.App.razor: Bootstrap CSS → Bootstrap Icons → app.css (project overrides) → Bootstrap JS Bundle → Blazor script.wwwroot/css/app.css — never inline style="" attributes..razor.css) for component-specific layout and spacing.--bs-*) in :root — never edit Bootstrap source files.--app-* prefix to avoid collisions with Bootstrap variables.[data-bs-theme] attribute — never a separate dark-mode CSS file.!important to override Bootstrap — fix specificity via correct selector order or custom properties.| Anti-Pattern | Fix |
|---|---|
| Business logic in .razor markup | Move to .razor.cs partial class |
| public mutable [Parameter] property | Use private set or init |
| Direct HTTP calls inside component | Inject typed API client service |
| StateHasChanged() called on every action | Let Blazor detect changes automatically |
| Static shared state class | Use scoped DI state service |
| Missing IDisposable on event subscriptions | Always unsubscribe in Dispose() |
| OnParametersSetAsync loading data unconditionally | Guard with a changed-parameter check |
| All logic in @code {} block instead of code-behind | Split into .razor (markup) + .razor.cs (logic) |
| Missing @using static RenderMode in _Imports.razor | Add @using static Microsoft.AspNetCore.Components.Web.RenderMode |
| New project not added to solution file | Always add to .sln/.slnx when scaffolding |
| Service call inside @foreach loop in markup | Pre-fetch data in code-behind; pass as parameter to child components |
| No CSS framework declared — ad-hoc styles | Default to Bootstrap 5; declare alternative in design artifact |
| Inline style="" attributes on components | Use CSS isolation (.razor.css) or global app.css |
| Mixing two CSS frameworks | Pick one framework and commit — never Bootstrap + Tailwind etc. |
| Hardcoded colors in component styles | Use CSS custom properties (--bs-* or --app-*) |
| !important to override Bootstrap | Fix specificity order; use custom properties |
| Editing Bootstrap source CSS | Override in app.css loaded after Bootstrap |
web-ui-styling skill — CSS framework decision matrix, Bootstrap setup, theming, CSS isolationsignalr.md — SignalR hub design, groups, streaming, authorizationauth.md — Authentication, authorization, OAuth/OIDC, secrets managementnaming.md — Naming conventions for types, methods, properties, namespacesmaui.md — .NET MAUI MVVM, navigation, lifecycle, platform servicestools
Use when cross-cutting concerns (logging, metrics, validation, authorization) are tangled into command handlers or service methods, when building database command pipelines with reorderable concerns, or when HTTP client pipelines or message handlers need composable, independently-replaceable processing stages. Covers ICommandInterceptor interface, InterceptorPipeline with reverse-chain construction, zero-cost Empty sentinel to skip overhead when no interceptors are registered, and ConfigureAwait(false) discipline for library code. Domain: Architecture, Cross-Cutting Concerns. Level: Intermediate. Tags: interceptor, pipeline, middleware, decorator, cross-cutting-concerns.
development
Use when writing integration tests for Razor Pages, MVC, or Minimal API applications to validate routing, middleware, page rendering, and HTTP behavior without a browser or live server, or when adding fast smoke tests to a CI pipeline. Covers WebApplicationFactory<Program> setup with public partial class Program, in-memory test server, AngleSharp HTML parsing, CSS selector assertions, redirect and status code testing, and a shared static fixture pattern for minimal per-test startup overhead. Domain: Testing, ASP.NET Core. Level: Intermediate. Tags: integration-testing, webapplicationfactory, razor-pages, anglesharp, http-testing.
development
Use when designing indexes for new tables, diagnosing slow queries that are not using indexes efficiently, reviewing index fragmentation and maintenance, or when the current indexing strategy results in key lookups, table scans, or missing index warnings. Covers clustered index key selection (narrow, unique, ever-increasing), non-clustered index design for query patterns, covering indexes with INCLUDE columns, filtered indexes for subset queries, composite index column ordering, DMV-based monitoring for missing and unused indexes, and rebuild vs reorganize maintenance thresholds. Domain: Database, Performance. Level: Intermediate. Tags: index, sql-server, covering-index, filtered-index, performance, dmv, maintenance.
development
Use when building a searchable in-memory catalog or registry for documentation sites, admin panels, or type/API browsers where you need keyword matching, fuzzy search, and ranked results without an external search engine or database. Covers RegistryService with weighted scoring across name, description, keywords, and method names; Levenshtein fuzzy matching; synonym expansion; category and subcategory filtering; and singleton DI registration for datasets of hundreds to low thousands of items. Domain: Search, Data Access Patterns. Level: Intermediate. Tags: search, registry, fuzzy-matching, in-memory, catalog, filtering.