Class ViewModelRegistry
public class ViewModelRegistry : IViewModelRegistry
- Inheritance
-
ViewModelRegistry
- Implements
- Derived
- Inherited Members
Constructors
ViewModelRegistry(ILogger<ViewModelRegistry>?)
public ViewModelRegistry(ILogger<ViewModelRegistry>? log = null)
Parameters
logILogger<ViewModelRegistry>
Methods
GetViewForViewModelDynamic(Type)
Like GetViewForViewModel<TViewModel>(TViewModel), but accepts a Type parameter instead of an instance.
public Type? GetViewForViewModelDynamic(Type viewModelType)
Parameters
viewModelTypeType
Returns
GetViewForViewModel<TViewModel>(TViewModel)
Retrieves the registered View type for a given ViewModel type, or null if no registration exists.
public Type? GetViewForViewModel<TViewModel>(TViewModel viewModel) where TViewModel : INotifyPropertyChanged
Parameters
viewModelTViewModel
Returns
Type Parameters
TViewModel
RegisterDynamic(Type, Type, bool)
Like Register<TViewModel, TComponent>(bool), but accepts Type parameters instead of generics.
Note that there are no runtime checks for the constraints that apply to the generic version of this method to allow usage with e.g. AOT compilation.
public void RegisterDynamic(Type viewModelType, Type componentType, bool noWarn = false)
Parameters
Register<TViewModel, TComponent>(bool)
Registers a View type for a given ViewModel type. TComponent must be an MvvmComponentBase<T>, not with an optional or owned viewmodel, because we pass a non-null ViewModel instance to the component when rendering. Without that constraint, it would be possible to register a component that doesn't accept the ViewModel as a parameter.
You may prefer using the source generator - see ViewModelForAttribute.
If you are not using trimming (enabled by default in Blazor WASM since .NET 6 with
dotnet publish) or AOT compilation, you may prefer using
AutoRegister() for automatic registration.
Otherwise, use this method to manually register all View/ViewModel pairs.
public void Register<TViewModel, TComponent>(bool noWarn = false) where TViewModel : INotifyPropertyChanged where TComponent : MvvmComponentBase<TViewModel>
Parameters
noWarnbool
Type Parameters
TViewModelTComponent