Namespace BlazorToolkit.Previews

Classes

CascadingValueSpec

A cascading value to supply to a component when it is rendered. The renderer wraps the previewed component in a CascadingValue<TValue> for each of these.

ComponentPreview<T>

Base class for defining component previews. Inherit from this class and use AddPreview() to define preview scenarios.

ComponentPreview<T>.PreviewBuilder

Builder for configuring a preview's parameters and services.

Preview

Represents a single preview configuration for a component.

PreviewDispatchProxy

Runtime dispatch handler for the stub produced by Mock<TService>(Action<IStub<TService>>). Returns configured values for set-up members and safe defaults for everything else. Async is determined by inspecting the method's return type — never by method name.

This is not a System.Reflection.DispatchProxy: the proxy type is emitted per load context by BlazorToolkit.Previews.StubProxyFactory and forwards every interface call here via Invoke(MethodInfo?, object?[]?). The framework's System.Reflection.DispatchProxy keeps a single process-global proxy assembly bound to the first load context, which breaks Mock<T> after a rebuild in the long-lived sidecar (the returned proxy implements the previous build's interface). See BlazorToolkit.Previews.StubProxyFactory.

PreviewHostBuilder

Fluent builder an IPreviewHost uses to declare the shared host environment. Asset paths may be project-relative, project-escaping (..</code>), or absolute; the render host reads and inlines them into a self-contained preview document (no live web server), confining every read to the files/folders you declare. Host-level services are registered into each preview's render container, so every component in the tree — including nested ones — resolves them without per-preview setup.

PreviewHttpMock

A routed set of stub HTTP responses the preview host returns without touching the network. Rules are matched in order by method + path; the first match wins, else Default, else a benign 200. Built via the WithHttpResponse(builder => ...) overload; the flat WithHttpResponse(content) overload maps to a single Default.

PreviewHttpResponse

A fixed HTTP response the preview host's stub HttpClient returns for every request.

PreviewHttpRule

One method+path match rule and the PreviewHttpResponse it returns.

Interfaces

IComponentPreview<TComponent>

Interface for component preview definitions.

IComponentTraceSink

The seam an instrumented component's emitted lifecycle proxy reports into. It lives in this authoring assembly on purpose: the render engine loads a user's built assembly into a dedicated ComponentAssemblyLoadContext that defers BlazorToolkit.Previews* to the default context, so the dynamically-emitted proxy (in the default context) and every other party agree on the same IComponentTraceSink type across the load-context boundary. Placing it in the engine (also a BlazorToolkit.Previews* name) would work too, but the public authoring package is the natural, always-loaded home for the shared contract.

Implementations are supplied by the engine and registered per render (static: one per preview provider; interactive: one per circuit). The proxy calls these on the render dispatcher, so implementations only need to be resilient to being read from another thread (the trace is harvested after the render quiesces).

IHttpMockBuilder

Fluent builder for a routed HTTP mock (.WithHttpResponse(r => r.OnGet(...).OnPost(...).Default(...))).

IHttpResponseBuilder

Fluent builder for a single stub HTTP response (status, body, media type).

IPreviewHost

Marker implemented once per project to declare the host environment for every preview in that project — the CSS/JS/asset context the previews render inside, plus services registered once for all of them. It is discovered by reflection (like IComponentPreview<TComponent>) and supplies solution-global defaults that each preview can extend/override via the ComponentPreview builder (WithStylesheets, WithScripts, WithAssetRoots, ConfigureServices, Inject, Mock, WithLayout).

Nothing is assumed or auto-discovered: previews render with exactly the assets and services you declare here (plus per-preview additions). Asset paths may be project-relative, escape the project (..\), or be absolute — the renderer honors exactly what you name and reads nothing outside the files/folders you declare. A project may declare at most one IPreviewHost; more than one is a configuration error surfaced back to the IDE.

IStub<TService>

Configures stub return values for a service being mocked via Mock<TService>(Action<IStub<TService>>). Arguments are ignored; unconfigured members return a safe default. There are no verifications or assertions — this is only enough to let a component render statically.

Enums

RenderStrategy

Which renderer a preview uses. Both renderers exist in the sidecar; this selects between them.