Class 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.

Inheritance
PreviewHostBuilder
Namespace: BlazorToolkit.Previews
Assembly: BlazorToolkit.Previews.dll
Syntax
public sealed class PreviewHostBuilder

Constructors

PreviewHostBuilder()

Declaration
public PreviewHostBuilder()

Properties

AssetRoots

Base folders used to resolve url(...)/@import and _content/* references found inside the declared CSS. These are the trust boundary: every file read is confined to the project directory, these declared roots, and the build's static-web-asset content roots.

Declaration
public List<string> AssetRoots { get; }
Property Value
Type Description
List<string>

DefaultLayout

Default layout (a LayoutComponentBase) that wraps every preview in this project as its Body, unless a preview overrides it with WithLayout<TLayout>(). Null means no layout (the previewed component renders bare). Set via UseLayout<TLayout>().

Declaration
public Type? DefaultLayout { get; }
Property Value
Type Description
Type

DefaultStrategy

Default renderer for every preview in this project, unless a preview overrides it with RenderInteractive()/RenderStatic(). Null means the framework default (Interactive). Set via RenderInteractive()/RenderStatic().

Declaration
public RenderStrategy? DefaultStrategy { get; }
Property Value
Type Description
RenderStrategy?

Scripts

Script paths, inlined as <script> into the default shell.

Declaration
public List<string> Scripts { get; }
Property Value
Type Description
List<string>

ServiceConfigurators

Service registrations applied to every preview's render container (the escape hatch for library Add* calls). Applied before per-preview registrations, so a preview can override them.

Declaration
public List<Action<IServiceCollection>> ServiceConfigurators { get; }
Property Value
Type Description
List<Action<IServiceCollection>>

Services

Explicit service instances (from Inject<TService>(TService)) shared by every preview.

Declaration
public Dictionary<Type, object> Services { get; }
Property Value
Type Description
Dictionary<Type, object>

Stylesheets

Stylesheet paths, inlined as <style> into the default shell.

Declaration
public List<string> Stylesheets { get; }
Property Value
Type Description
List<string>

Methods

AddAssetRoots(params string[])

Adds one or more base folders for resolving CSS asset references. Folders may be project-relative, escape the project (..</code>), or be absolute. See AssetRoots.

Declaration
public PreviewHostBuilder AddAssetRoots(params string[] folders)
Parameters
Type Name Description
string[] folders
Returns
Type Description
PreviewHostBuilder

AddScripts(params string[])

Adds one or more scripts inlined into every preview. Paths may be project-relative, escape the project (..</code>), or be absolute.

Declaration
public PreviewHostBuilder AddScripts(params string[] paths)
Parameters
Type Name Description
string[] paths
Returns
Type Description
PreviewHostBuilder

AddStylesheets(params string[])

Adds one or more stylesheets inlined into every preview. Paths may be project-relative, escape the project (..</code>), or be absolute.

Declaration
public PreviewHostBuilder AddStylesheets(params string[] paths)
Parameters
Type Name Description
string[] paths
Returns
Type Description
PreviewHostBuilder

ConfigureServices(Action<IServiceCollection>)

Registers services into every preview's render container — the escape hatch for component libraries (e.g. .ConfigureServices(s => s.AddMudServices())). Runs before per-preview registrations.

Declaration
public PreviewHostBuilder ConfigureServices(Action<IServiceCollection> configure)
Parameters
Type Name Description
Action<IServiceCollection> configure
Returns
Type Description
PreviewHostBuilder

Inject<TService>(TService)

Injects a real service instance shared by every preview (and every nested component). A per-preview Inject/Mock/ConfigureServices for the same type overrides it.

Declaration
public PreviewHostBuilder Inject<TService>(TService instance) where TService : class
Parameters
Type Name Description
TService instance
Returns
Type Description
PreviewHostBuilder
Type Parameters
Name Description
TService

RenderInteractive()

Makes the live Blazor Server circuit (prerender off) the default renderer for every preview in this project. This is already the framework default; call it only to be explicit. A preview may still opt into RenderStatic().

Declaration
public PreviewHostBuilder RenderInteractive()
Returns
Type Description
PreviewHostBuilder

RenderStatic()

Makes the static SSR renderer (no circuit) the default for every preview in this project — e.g. a pure-SSR site with no interactive components. A preview may still opt into RenderInteractive().

Declaration
public PreviewHostBuilder RenderStatic()
Returns
Type Description
PreviewHostBuilder

UseLayout<TLayout>()

Wraps every preview in this project in a layout (a LayoutComponentBase), rendering the component as the layout's Body. Use it to place previews inside app chrome, a state/context provider, or several nested providers authored as one layout. A preview can swap in a different layout with WithLayout<TLayout>().

Declaration
public PreviewHostBuilder UseLayout<TLayout>() where TLayout : LayoutComponentBase
Returns
Type Description
PreviewHostBuilder
Type Parameters
Name Description
TLayout

The default layout component to wrap every preview with.