Table of Contents

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 : IViewModelBase

Type 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

IParameterResolver

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

disposing bool

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

ValueTask

A ValueTask representing the asynchronous dispose operation.

DisposeAsyncCore()

Disposes the component asynchronously and releases unmanaged resources for the scoped services.

protected virtual ValueTask DisposeAsyncCore()

Returns

ValueTask

A ValueTask representing the asynchronous dispose operation.

OnAfterRender(bool)

Invoked after the component has rendered.

protected override void OnAfterRender(bool firstRender)

Parameters

firstRender bool

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

firstRender bool

True if this is the first time OnAfterRenderAsync(bool) is called; otherwise, false.

Returns

Task

A Task representing the asynchronous operation.

OnInitialized()

Initializes the component and subscribes to ViewModel property changes.

protected override void OnInitialized()

OnInitializedAsync()

Asynchronously initializes the component.

protected override Task OnInitializedAsync()

Returns

Task

A Task representing the asynchronous operation.

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

Task

A Task representing the asynchronous operation.

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

parameters ParameterView

The parameters to set.

Returns

Task

A Task representing the asynchronous operation.

ShouldRender()

Determines whether the component should render.

protected override bool ShouldRender()

Returns

bool

true if the component should render; otherwise, false.