ReactiveServiceCollectionExtensions class

Namespace Runic.Application.Views.ReactiveUI.Reactive in Runic.Application.Views.ReactiveUI.Reactive 0.23.0

public static class ReactiveServiceCollectionExtensions

Registers ReactiveUI scheduling for a scoped Runic model graph.

Methods

AddRunicReactiveModelContext

public static IServiceCollection AddRunicReactiveModelContext(this IServiceCollection services)

Adds a scoped model context, the scheduler provider and the scheduler of that context, and installs the model-context main-thread scheduler (ReactiveSchedulers.InstallMainThreadScheduler), so ReactiveUI commands created without an output scheduler deliver their notifications on the model context that executes them. Existing application registrations are preserved. To opt out, set RxSchedulers.MainThreadScheduler, or call WithMainThreadScheduler on ReactiveUI's builder, before AddRunicReactiveModelContext(), or replace it afterwards.

Remarks

The scheduler is registered as transient, and the provider returns one scheduler per context, so every resolution for one context gets the same instance. That also holds when the context is a singleton, such as a WPF dispatcher context, and a singleton ViewModel can inject it. The CS-WebUI, Desktop and WPF hosts bind a window's root ViewModel to the scoped context, the window binds each child ViewModel it presents, and a navigator binds the entries it owns, so ViewModels need no RunicModelContextRegistry.Bind call. A ViewModel bound to another context is rejected when presented. Dispose the service scope asynchronously to drain its owned context. An application that builds ReactiveUI with RxAppBuilder also calls ReactiveUIBuilderExtensions.WithRunicModelContext there, so its BuildApp() keeps the scheduler. When a Runic Desktop, CS-WebUI or test-host window opens, the installed scheduler logs through the application's ILoggerFactory, and a scheduler that was kept or that replaced it is logged as Views event 1090 or 1091.