blazor-hexagonal

Separate Blazor UI rendering from logic using presenter classes and fake gateways.

Updated Apr 1, 2026
One-click install
npx skills add https://github.com/FoxSilou/ConfigurationClaude --skill blazor-hexagonal
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: blazor-hexagonal
Source: https://github.com/FoxSilou/ConfigurationClaude/tree/main/frontend/.claude/skills/blazor-hexagonal
Command: npx skills add https://github.com/FoxSilou/ConfigurationClaude --skill blazor-hexagonal

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

This skill removes UI logic from Blazor components by applying a hexagonal frontend architecture so that UI behavior is fully testable, predictable, and decoupled from rendering concerns.

Core Features & Use Cases

  • Presenter-driven UI: Move state, transitions, and visibility logic into Presenter classes placed in a UI.Domain layer with zero Blazor dependencies.
  • Test-first workflow: Templates and guidance for writing Presenter unit tests using Fake Gateways to drive TDD for visibility, state machines, and error scenarios.
  • Ports and Gateways: Define ports as interfaces and implement HTTP adapters in infrastructure so presenters remain pure; use Fake Gateways for fast, synchronous tests.
  • Field Presenters & Validation: Strong typed field presenters with Valide types and Result<T> for safe, immutable form state and validation.
  • DI and wiring checks: Explicit guidance to register gateways with AddHttpClient and presenters as Scoped, plus UI update safety using InvokeAsync(StateHasChanged) and IDisposable unsubscribe patterns.

Quick Start

Create a Presenter with a Fake gateway, write a failing unit test that asserts the desired visibility or state transition, implement the minimal Presenter logic to pass the test, and then wire a thin .razor component that injects and binds to the Presenter.

Frequently Asked Questions about blazor-hexagonal

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I separate UI logic from Blazor components to make it testable?

To separate UI logic from Blazor components, move state transitions and visibility logic into Presenter classes within a UI.Domain layer that has zero Blazor dependencies. This enables fully testable presenters while keeping .razor files thin and focused on rendering.

What's the best way to TDD Blazor frontend state machines and error handling?

The best way to TDD Blazor frontend state machines is to write failing unit tests against Presenter classes using Fake Gateways. Implement minimal Presenter logic to pass tests for visibility, state transitions, and error scenarios, then wire a thin Blazor component to the Presenter.

How does hexagonal frontend architecture work with Blazor dependency injection?

Hexagonal frontend architecture in Blazor uses dependency injection by defining ports as interfaces and registering HTTP adapter gateways with AddHttpClient. Presenters remain pure by depending on these interfaces and are registered using AddScoped for proper component lifecycle management.

Can I use Fake Gateways for synchronous Blazor unit tests instead of mocking HTTP calls?

Yes, you can use Fake Gateways for fast, synchronous Blazor unit tests. Define ports as interfaces and implement Fake Gateways in your test project so presenters remain pure. This allows driving TDD workflows for visibility control and state machines without actual HTTP overhead.

How do I prevent memory leaks when binding Blazor components to Presenter state updates?

To prevent memory leaks when binding Blazor components to Presenters, use InvokeAsync(StateHasChanged) for thread-safe UI updates and implement IDisposable in your components. This unsubscription pattern ensures that event handlers are detached when the Blazor component is disposed.

How do I handle form state and validation safely in Blazor without direct UI dependencies?

To handle form state safely without UI dependencies, use strongly typed field presenters with Valide types and Result<T> patterns. This ensures immutable form state and safe validation logic resides in the UI.Domain layer, completely decoupled from Blazor rendering concerns.