RunicWindowHostExtensions class

Namespace Runic.Application.Views in Runic.Application.Views 0.23.0

public static class RunicWindowHostExtensions

Opens and validates Windows on any IRunicWindowHost.

Methods

OpenWindowAsync

public static ValueTask<TWindow> OpenWindowAsync<TWindow>(this IRunicWindowHost host, RunicWindowOptions? options = null, CancellationToken cancellationToken = default) where TWindow : class, IRunicWindow, new()

Creates TWindow, resolves its ViewModel in a new DI scope, and opens it on host. Release the Window with await using.

Parameters

host

The host, such as the one RunicDesktopHost.Run passes to the application.

options

The content and size; null opens www/index.html next to the application.

cancellationToken

Cancels opening. A cancelled open releases everything it created.

Returns

The open Window.

Exceptions

RunicWindowConfigurationException

A check failed before anything opened, for example no generated Bridge is registered for the ViewModel (RunicWindowConfigurationException.BridgeNotRegisteredCode), or the host rejected the window configuration.

OpenWindowAsync

public static ValueTask<TWindow> OpenWindowAsync<TWindow, TParameter>(this IRunicWindowHost host, TParameter parameter, RunicWindowOptions? options = null, CancellationToken cancellationToken = default) where TWindow : class, IRunicWindow, new() where TParameter : class

Opens TWindow as RunicWindowHostExtensions.OpenWindowAsync does, and hands parameter to its new scope: the Window's ViewModel, and every service of that scope, takes IRunicWindowParameter in its constructor and reads it from there.

Parameters

host

The host, such as the one RunicDesktopHost.Run passes to the application.

parameter

The value the new Window's scope receives.

options

The content and size; null opens www/index.html next to the application.

cancellationToken

Cancels opening. A cancelled open releases everything it created.

Returns

The open Window.

Exceptions

RunicWindowConfigurationException

A check failed before anything opened, for example RunicWindowServiceCollectionExtensions.AddRunicWindowService was not called (RunicWindowConfigurationException.WindowParameterNotRegisteredCode).

Remarks

await host.OpenWindowAsync<DocumentWindow, DocumentRequest>(new DocumentRequest(path));

public sealed class DocumentViewModel(IRunicWindowParameter<DocumentRequest> request) { ... }

The parameter belongs to this Window only: another Window, opened at the same time, gets its own. It needs RunicWindowServiceCollectionExtensions.AddRunicWindowService in the application's services.

ValidateWindow

public static RunicWindowValidationResult ValidateWindow<TWindow>(this IRunicWindowHost host, RunicWindowOptions? options = null) where TWindow : class, IRunicWindow, new()

Checks at startup, before any window opens, that host can open TWindow with options: the generated Bridge registration (an error when missing), the ViewModel registration (a warning when the container does not confirm it), and the host's own presentation checks.

Remarks

Registrations are checked through IServiceProviderIsService without constructing anything; containers without it are not checked here, and opening still reports a missing Bridge before any window exists. Errors are logged through the provider's ILoggerFactory (event 1050). Call RunicWindowValidationResult.ThrowIfInvalid to stop at startup.