Class MvvmOwningComponentBase<TViewModel>
- Namespace
- Blazing.Mvvm.Components
- Assembly
- Blazing.Mvvm.dll
A base class for Blazor components that create a service provider scope and resolve a ViewModel of type TViewModel.
public abstract class MvvmOwningComponentBase<TViewModel> : OwningComponentBase, IComponent, IHandleEvent, IHandleAfterRender, IView<TViewModel>, IView, IDisposable, IAsyncDisposable where TViewModel : IViewModelBaseType Parameters
TViewModel-
The type of the ViewModel associated with this component. Must implement IViewModelBase.
Inheritance
Implements
Inherited Members
Remarks
Use MvvmOwningComponentBase<TViewModel> as a base class to author components that control the lifetime of a ViewModel and a service provider scope. This is useful when using a transient or scoped service that requires disposal, such as a repository or database abstraction. Using MvvmOwningComponentBase<TViewModel> ensures that the ViewModel and related services sharing its scope are disposed with the component.
Properties
ParameterResolver
Gets or sets the parameter resolver used to set parameters on the View and ViewModel.
[Inject]
protected IParameterResolver ParameterResolver { get; set; }Property Value
ViewModel
Gets or sets the ViewModel associated with this component, resolved from the Microsoft.AspNetCore.Components.OwningComponentBase.ScopedServices.
protected virtual TViewModel ViewModel { get; set; }Property Value
- TViewModel
Methods
Dispose(bool)
Disposes the component and releases unmanaged resources.
protected override void Dispose(bool disposing)Parameters
disposingbool-
True if called from the public Dispose method; false if called from a finalizer.
DisposeAsync()
Disposes the component asynchronously and releases unmanaged resources.
public ValueTask DisposeAsync()Returns
DisposeAsyncCore()
Disposes the component asynchronously and releases unmanaged resources for the scoped services.
protected virtual ValueTask DisposeAsyncCore()Returns
OnAfterRender(bool)
Invoked after the component has rendered.
protected override void OnAfterRender(bool firstRender)Parameters
firstRenderbool-
True if this is the first time OnAfterRender(bool) is called; otherwise, false.
OnAfterRenderAsync(bool)
Asynchronously invoked after the component has rendered.
protected override Task OnAfterRenderAsync(bool firstRender)Parameters
firstRenderbool-
True if this is the first time OnAfterRenderAsync(bool) is called; otherwise, false.
Returns
OnInitialized()
Initializes the component and subscribes to ViewModel property changes.
protected override void OnInitialized()OnInitializedAsync()
Asynchronously initializes the component.
protected override Task OnInitializedAsync()Returns
OnParametersSet()
Sets parameters on the component and ViewModel.
protected override void OnParametersSet()OnParametersSetAsync()
Asynchronously sets parameters on the component and ViewModel.
protected override Task OnParametersSetAsync()Returns
SetParametersAsync(ParameterView)
Sets parameters from the given Microsoft.AspNetCore.Components.ParameterView on both the View and its ViewModel using the ParameterResolver.
public override Task SetParametersAsync(ParameterView parameters)Parameters
parametersParameterView-
The parameters to set.
Returns
ShouldRender()
Determines whether the component should render.
protected override bool ShouldRender()Returns
- bool
-
trueif the component should render; otherwise,false.