Skip to content

DefaultViewLocator class

Attributes: [DebuggerDisplay("Mappings = {_mappings.Count}")]

Defined in

Namespace: ReactiveUI Assembly: ReactiveUI.Core.dll Full name: ReactiveUI.DefaultViewLocator Modifiers: public sealed

Summary

View source

Default AOT-compatible implementation of IViewLocator that resolves views using compile-time registrations.

Applies to

net10.0, net10.0-maccatalyst26.0, net10.0-desktop1.0, net10.0-browserwasm1.0, net10.0-tvos26.0, net10.0-windows10.0.19041, net10.0-macos26.0, net10.0-ios26.0, net10.0-android36.0, net9.0, net9.0-tvos18.0, net9.0-macos15.0, net9.0-maccatalyst18.0, net9.0-windows10.0.19041, net9.0-ios18.0, net9.0-desktop1.0, net8.0, net8.0-windows10.0.19041, net8.0-ios18.0, net8.0-maccatalyst18.0, net8.0-macos15.0, net8.0-tvos18.0, net8.0-ios17.5, net8.0-maccatalyst17.5, net8.0-macos14.5, netstandard2.1, net481, net462, net471

Class hierarchy
classDiagram
class DefaultViewLocator
class IViewLocator {
    <>
}
IViewLocator <|.. DefaultViewLocator
class IEnableLogger {
    <>
}
IEnableLogger <|.. DefaultViewLocator

Implements: IViewLocator, IEnableLogger

Remarks

This locator uses explicit view-to-viewmodel mappings registered via Map. When no mapping is found, it falls back to querying the service locator for IViewFor<TViewModel>.

This implementation is fully AOT-compatible and does not use reflection or runtime type discovery. All view-viewmodel associations must be registered at application startup.

Examples

<![CDATA[
 // Register views at startup
 var locator = new DefaultViewLocator();
 locator.Map<LoginViewModel, LoginView>(() => new LoginView())
 .Map<MainViewModel, MainView>(() => new MainView())
 .Map<SettingsViewModel, SettingsView>(() => new SettingsView());
 
 // Resolve at runtime (fully AOT-compatible)
 var view = locator.ResolveView<LoginViewModel>();
 ]]>

Constructors

NameSummary
.ctor

Methods

NameSummary
MapRegisters a direct mapping from a view model type to a view factory using the default contract.
UnmapRemoves the default view mapping for the given view model type.
ResolveViewResolves a view for a view model type using the default contract. Fully AOT-compatible.
Inherited members