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

Namespace: BlazorToolkit.Previews
Assembly: BlazorToolkit.Previews.dll
Syntax
public interface IPreviewHost
Examples
public class PreviewHost : IPreviewHost
{
    public void Configure(PreviewHostBuilder host) => host
        // Assets live in a sibling web app — point at them explicitly:
        .AddAssetRoots(@"..\MyApp.Web\wwwroot")
        .AddStylesheets(
            @"..\MyApp.Web\wwwroot\lib\bootstrap\dist\css\bootstrap.min.css",
            @"..\MyApp.Web\wwwroot\css\site.css")
        .AddScripts(@"..\MyApp.Web\wwwroot\lib\bootstrap\dist\js\bootstrap.bundle.min.js")
        // Services shared by every preview (and every nested component they render):
        .ConfigureServices(s => s.AddMyAppServices())
        .Inject<IClock>(new FixedClock(new DateTime(2025, 1, 1)));
}

Methods

Configure(PreviewHostBuilder)

Declares the shared host environment applied to all previews in this project.

Declaration
void Configure(PreviewHostBuilder host)
Parameters
Type Name Description
PreviewHostBuilder host