AppStateBase

A base class to control application-wide state in a Blazor app.

Syntax

public class AppStateBase : BlazorObservable, INotifyPropertyChanged, IDisposable

Inheritance

Implements

Constructors

AppStateBase

public AppStateBase(NavigationManager navigationManager, IHttpClientFactory httpClientFactory, IJSRuntime jsRuntime, IWebAssemblyHostEnvironment environment, NavigationHistory navHistory, StateHasChangedConfig stateHasChangedConfig = null)

Parameters

Properties

AuthenticationStateProvider

public AuthenticationStateProvider AuthenticationStateProvider { get; set; }
The instance for the application.

Returns

AuthenticationStateProvider

ClaimsPrincipal

public ClaimsPrincipal ClaimsPrincipal { get; set; }
The returned from calling .

Returns

ClaimsPrincipal

CurrentNavItem

public NavigationItem CurrentNavItem { get; set; }
The from that corresponds to the current Route.

Returns

NavigationItem

Environment

public IWebAssemblyHostEnvironment Environment { get; set; }
The injected from the DI container.

Returns

IWebAssemblyHostEnvironment

HttpClientFactory

public IHttpClientFactory HttpClientFactory { get; }
The instance of the injected by the DI system.

Returns

IHttpClientFactory

IsClaimsPrincipalAuthenticated

public bool IsClaimsPrincipalAuthenticated { get; }
Returns a value indicating whether or not the current Identity is authenticated.

Returns

bool

JSRuntime

public IJSRuntime JSRuntime { get; set; }

Returns

IJSRuntime
public NavigationHistory NavigationHistory { get; }
Allows the application to interact with the browser’s History API.

Returns

NavigationHistory
public NavigationManager NavigationManager { get; }
The instance of the injected by the DI system.

Returns

NavigationManager
public ObservableCollection<NavigationItem> NavItems { get; }
An containing the primary navigation details for the application.

Returns

ObservableCollection<NavigationItem>

Methods

Dispose

protected override void Dispose(bool disposing)

Parameters

LoadNavItems

public void LoadNavItems(List<NavigationItem> items)
Load the NavigationItems into and properly wire up the PropertyChanged event.

Parameters

public void Navigate(string uri, bool setCurrentNavItem = false)
Navigates to the specified Uri and sets to the matching in .

Parameters

  • uri string:
  • setCurrentNavItem bool: Determines whether or not we should also set the CurrentNavItem. Usually this is no because the MainLayout should call AppState.SetCurrentNavItem in OnParametersSet. This parameter gives you flexibility without potentially calling it twice.
public Task NavigateBackAsync(bool setCurrentNavItem = false)
Utilizes the injected History API to navigate to the last entry in the history stack, and attempts to set the .

Parameters

  • setCurrentNavItem bool: Determines whether or not we should also set the CurrentNavItem. Usually this is no because the MainLayout should call AppState.SetCurrentNavItem in OnParametersSet. This parameter gives you flexibility without potentially calling it twice.

Returns

Task A representing the completion state of the operation.
public Task NavigateForwardAsync(bool setCurrentNavItem = false)
Utilizes the injected History API to navigate to the next entry in the history stack, and attempts to set the .

Parameters

  • setCurrentNavItem bool: Determines whether or not we should also set the CurrentNavItem. Usually this is no because the MainLayout should call AppState.SetCurrentNavItem in OnParametersSet. This parameter gives you flexibility without potentially calling it twice.

Returns

Task A representing the completion state of the operation.

OpenInNewTab

public Task OpenInNewTab(string url)

Parameters

Returns

Task

RefreshClaimsPrincipal

public Task RefreshClaimsPrincipal()
Tells the AuthenticationProvider to get the latest ClaimsPrincipal and run it through the internal AuthenticationStateChanged handler.

Returns

Task A representing the completion state of the operation.

SetCurrentNavItem

public void SetCurrentNavItem()
Initializes to the proper value based on the current route.

SetCurrentNavItem

public void SetCurrentNavItem(string url)
Initializes to the proper value based on the current route.

Parameters