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
| Name | Type | Description |
navigationManager | Microsoft.AspNetCore.Components.NavigationManager | The Blazor AppStateBase.NavigationManager instance from the DI container. |
httpClientFactory | System.Net.Http.IHttpClientFactory | The IHttpClientFactory instance from the DI container. |
jsRuntime | Microsoft.JSInterop.IJSRuntime | The IJSRuntime instance from the DI container. |
environment | Microsoft.AspNetCore.Components.WebAssembly.Hosting.IWebAssemblyHostEnvironment | The IWebAssemblyHostEnvironment instance from the DI container. |
navHistory | CloudNimble.BlazorEssentials.Navigation.NavigationHistory | The AppStateBase.NavigationHistory instance from the DI container. |
stateHasChangedConfig | CloudNimble.BlazorEssentials.StateHasChangedConfig | The 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
| Name | Type | Description |
stateHasChangedConfig | CloudNimble.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
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
NavigationHistory
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
This really should be a part of the NavigationManager, but what do we know? ¯_(ツ)_/¯
NavigationManager
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
NavItems
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
| Name | Type | Description |
disposing | bool | - |
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
| Name | Type | Description |
items | System.Collections.Generic.List<CloudNimble.BlazorEssentials.Navigation.NavigationItem> | - |
Navigate
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
| Name | Type | Description |
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. | | |
NavigateBackAsync
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
| Name | Type | Description |
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
Type: System.Threading.Tasks.Task
A Task representing the completion state of the operation.
Will not throw an exception if you are at the bottom of the History stack.
NavigateForwardAsync
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
| Name | Type | Description |
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
Type: System.Threading.Tasks.Task
A Task representing the completion state of the operation.
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
| Name | Type | Description |
url | string | - |
Returns
Type: System.Threading.Tasks.Task
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
| Name | Type | Description |
url | string | - |