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
Assembly: BlazorToolkit.Previews.dll
public sealed class PreviewHostBuilder
Constructors
Declaration
public PreviewHostBuilder()
Properties
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
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
Declaration
public RenderStrategy? DefaultStrategy { get; }
Property Value
Script paths, inlined as <script> into the default shell.
Declaration
public List<string> Scripts { get; }
Property Value
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
Declaration
public Dictionary<Type, object> Services { get; }
Property Value
Stylesheet paths, inlined as <style> into the default shell.
Declaration
public List<string> Stylesheets { get; }
Property Value
Methods
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
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
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
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
Returns
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 Parameters
| Name |
Description |
| TService |
|
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
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
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 Parameters
| Name |
Description |
| TLayout |
The default layout component to wrap every preview with.
|