Skip to main content

Definition

Assembly: CloudNimble.BlazorEssentials.dll Namespace: CloudNimble.BlazorEssentials Inheritance: CloudNimble.BlazorEssentials.BlazorObservable

Syntax

CloudNimble.BlazorEssentials.AppStateBase

Summary

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

Constructors

.ctor

Syntax

public AppStateBase(Microsoft.AspNetCore.Components.NavigationManager navigationManager, System.Net.Http.IHttpClientFactory httpClientFactory, Microsoft.JSInterop.IJSRuntime jsRuntime, Microsoft.AspNetCore.Components.WebAssembly.Hosting.IWebAssemblyHostEnvironment environment, CloudNimble.BlazorEssentials.Navigation.NavigationHistory navHistory, CloudNimble.BlazorEssentials.StateHasChangedConfig stateHasChangedConfig = null)

Parameters

NameTypeDescription
navigationManagerMicrosoft.AspNetCore.Components.NavigationManagerThe Blazor AppStateBase.NavigationManager instance from the DI container.
httpClientFactorySystem.Net.Http.IHttpClientFactoryThe IHttpClientFactory instance from the DI container.
jsRuntimeMicrosoft.JSInterop.IJSRuntimeThe IJSRuntime instance from the DI container.
environmentMicrosoft.AspNetCore.Components.WebAssembly.Hosting.IWebAssemblyHostEnvironmentThe IWebAssemblyHostEnvironment instance from the DI container.
navHistoryCloudNimble.BlazorEssentials.Navigation.NavigationHistoryThe AppStateBase.NavigationHistory instance from the DI container.
stateHasChangedConfigCloudNimble.BlazorEssentials.StateHasChangedConfigThe StateHasChangedConfig instance from the DI container.

.ctor Inherited

Inherited from CloudNimble.BlazorEssentials.BlazorObservable
Creates a new instance of the BlazorObservable class.

Syntax

public BlazorObservable(CloudNimble.BlazorEssentials.StateHasChangedConfig stateHasChangedConfig = null)

Parameters

NameTypeDescription
stateHasChangedConfigCloudNimble.BlazorEssentials.StateHasChangedConfig-

Properties

AuthenticationStateProvider

The AppStateBase.AuthenticationStateProvider instance for the application.

Syntax

public Microsoft.AspNetCore.Components.Authorization.AuthenticationStateProvider AuthenticationStateProvider { get; set; }

Property Value

Type: Microsoft.AspNetCore.Components.Authorization.AuthenticationStateProvider

Remarks

This property correctly registers for and de-registers from AppStateBase.AuthenticationStateProvider events as the value is set, and automatically calls AppStateBase.RefreshClaimsPrincipal for you.

ClaimsPrincipal

The AppStateBase.ClaimsPrincipal returned from calling User.

Syntax

public System.Security.Claims.ClaimsPrincipal ClaimsPrincipal { get; set; }

Property Value

Type: System.Security.Claims.ClaimsPrincipal

CurrentNavItem

The NavigationItem from AppStateBase.NavItems that corresponds to the current Route.

Syntax

public CloudNimble.BlazorEssentials.Navigation.NavigationItem CurrentNavItem { get; set; }

Property Value

Type: CloudNimble.BlazorEssentials.Navigation.NavigationItem

Environment

The WebAssemblyHostEnvironment injected from the DI container.

Syntax

public Microsoft.AspNetCore.Components.WebAssembly.Hosting.IWebAssemblyHostEnvironment Environment { get; set; }

Property Value

Type: Microsoft.AspNetCore.Components.WebAssembly.Hosting.IWebAssemblyHostEnvironment

HttpClientFactory

The instance of the IHttpClientFactory injected by the DI system.

Syntax

public System.Net.Http.IHttpClientFactory HttpClientFactory { get; private set; }

Property Value

Type: System.Net.Http.IHttpClientFactory

IsClaimsPrincipalAuthenticated

Returns a value indicating whether or not the current AppStateBase.ClaimsPrincipalClaimsPrincipal’s</see> Identity is authenticated.

Syntax

public bool IsClaimsPrincipalAuthenticated { get; }

Property Value

Type: bool

JSRuntime

Syntax

public Microsoft.JSInterop.IJSRuntime JSRuntime { get; set; }

Property Value

Type: Microsoft.JSInterop.IJSRuntime

LoadingStatus Inherited

Inherited from CloudNimble.BlazorEssentials.BlazorObservable
A BlazorObservable.LoadingStatus specifying the current state of the required data for this Observable.

Syntax

public CloudNimble.BlazorEssentials.LoadingStatus LoadingStatus { get; set; }

Property Value

Type: CloudNimble.BlazorEssentials.LoadingStatus Allows the application to interact with the browser’s History API.

Syntax

public CloudNimble.BlazorEssentials.Navigation.NavigationHistory NavigationHistory { get; private set; }

Property Value

Type: CloudNimble.BlazorEssentials.Navigation.NavigationHistory

Remarks

This really should be a part of the NavigationManager, but what do we know? ¯_(ツ)_/¯ The instance of the AppStateBase.NavigationManager injected by the DI system.

Syntax

public Microsoft.AspNetCore.Components.NavigationManager NavigationManager { get; private set; }

Property Value

Type: Microsoft.AspNetCore.Components.NavigationManager An ObservableCollection`1 containing the primary navigation details for the application.

Syntax

public System.Collections.ObjectModel.ObservableCollection<CloudNimble.BlazorEssentials.Navigation.NavigationItem> NavItems { get; internal set; }

Property Value

Type: System.Collections.ObjectModel.ObservableCollection<CloudNimble.BlazorEssentials.Navigation.NavigationItem>

StateHasChanged Inherited

Inherited from CloudNimble.BlazorEssentials.BlazorObservable
Determines how to trigger StateHasChanged events in a Blazor component.

Syntax

public CloudNimble.BlazorEssentials.StateHasChangedConfig StateHasChanged { get; set; }

Property Value

Type: CloudNimble.BlazorEssentials.StateHasChangedConfig

Methods

Dispose Override

Inherited from CloudNimble.BlazorEssentials.BlazorObservable

Syntax

protected override void Dispose(bool disposing)

Parameters

NameTypeDescription
disposingbool-

LoadNavItems

Load the NavigationItems into AppStateBase.NavItems and properly wire up the PropertyChanged event.

Syntax

public void LoadNavItems(System.Collections.Generic.List<CloudNimble.BlazorEssentials.Navigation.NavigationItem> items)

Parameters

NameTypeDescription
itemsSystem.Collections.Generic.List<CloudNimble.BlazorEssentials.Navigation.NavigationItem>-
Navigates to the specified Uri and sets AppStateBase.CurrentNavItem to the matching NavigationItem in AppStateBase.NavItems.

Syntax

public void Navigate(string uri, bool setCurrentNavItem = false)

Parameters

NameTypeDescription
uristring-
setCurrentNavItemboolDetermines 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.
Utilizes the injected AppStateBase.NavigationHistory History API to navigate to the last entry in the history stack, and attempts to set the AppStateBase.CurrentNavItem.

Syntax

public System.Threading.Tasks.Task NavigateBackAsync(bool setCurrentNavItem = false)

Parameters

NameTypeDescription
setCurrentNavItemboolDetermines 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

Type: System.Threading.Tasks.Task A Task representing the completion state of the operation.

Remarks

Will not throw an exception if you are at the bottom of the History stack. Utilizes the injected AppStateBase.NavigationHistory History API to navigate to the next entry in the history stack, and attempts to set the AppStateBase.CurrentNavItem.

Syntax

public System.Threading.Tasks.Task NavigateForwardAsync(bool setCurrentNavItem = false)

Parameters

NameTypeDescription
setCurrentNavItemboolDetermines 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

Type: System.Threading.Tasks.Task A Task representing the completion state of the operation.

Remarks

Will not throw an exception if you are at the top of the History stack.

OpenInNewTab

Syntax

public System.Threading.Tasks.Task OpenInNewTab(string url)

Parameters

NameTypeDescription
urlstring-

Returns

Type: System.Threading.Tasks.Task

Remarks

https://stackoverflow.com/a/62769092

RefreshClaimsPrincipal

Tells the AuthenticationProvider to get the latest ClaimsPrincipal and run it through the internal AuthenticationStateChanged handler.

Syntax

public System.Threading.Tasks.Task RefreshClaimsPrincipal()

Returns

Type: System.Threading.Tasks.Task A Task representing the completion state of the operation.

SetCurrentNavItem

Initializes AppStateBase.CurrentNavItem to the proper value based on the current route.

Syntax

public void SetCurrentNavItem()

SetCurrentNavItem

Initializes AppStateBase.CurrentNavItem to the proper value based on the current route.

Syntax

public void SetCurrentNavItem(string url)

Parameters

NameTypeDescription
urlstring-