Table of Contents

Class MvvmManager

Namespace
Crystal.Avalonia
Assembly
Crystal.Avalonia.dll

Holds View-to-ViewModel mappings and the application IServiceProvider for a single CrystalApplication instance.

public sealed class MvvmManager
Inheritance
MvvmManager
Inherited Members

Remarks

After registering View/ViewModel pairs via AddMvvmTransient<TView, TViewModel>(IServiceCollection) or AddMvvmSingleton<TView, TViewModel>(IServiceCollection), the system will:

  • Register the ViewModel in DI
  • Record the View ↔ ViewModel type mapping (TView is not registered in DI)
  • Inject the DataContext via ViewModelLocator when AutoWireViewModel is set
  • Instantiate the corresponding View via ViewLocator when EnableViewLocator is enabled on app options

Properties

ServiceProvider

Gets or sets the current application's service provider. Assigned by CrystalApplication after the container is built, before module initialization.

public IServiceProvider? ServiceProvider { get; set; }

Property Value

IServiceProvider

Methods

GetViewType(Type)

Looks up the View type corresponding to the given ViewModel type.

[UnconditionalSuppressMessage("Trimming", "IL2073", Justification = "View types are registered via AddMvvm* with PublicConstructors annotation.")]
public Type? GetViewType(Type vmType)

Parameters

vmType Type

The ViewModel type.

Returns

Type

The corresponding View type, or null if not found.

GetVmType(Type)

Looks up the ViewModel type corresponding to the given View type.

public Type? GetVmType(Type viewType)

Parameters

viewType Type

The View type.

Returns

Type

The corresponding ViewModel type, or null if not found.