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 (
TViewis not registered in DI) - Inject the DataContext via ViewModelLocator when
AutoWireViewModelis 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
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
vmTypeTypeThe ViewModel type.
Returns
- Type
The corresponding View type, or
nullif not found.
GetVmType(Type)
Looks up the ViewModel type corresponding to the given View type.
public Type? GetVmType(Type viewType)
Parameters
viewTypeTypeThe View type.
Returns
- Type
The corresponding ViewModel type, or
nullif not found.