Table of Contents

Class SessionStorageService

Namespace
NuvTools.AspNetCore.Blazor.JSInterop
Assembly
NuvTools.AspNetCore.Blazor.dll

Provides JavaScript interop functionality for browser sessionStorage operations.

public sealed class SessionStorageService : ISessionStorageService
Inheritance
SessionStorageService
Implements
Inherited Members

Remarks

Initializes a new instance of the SessionStorageService class.

Constructors

SessionStorageService(IJSRuntime)

Provides JavaScript interop functionality for browser sessionStorage operations.

public SessionStorageService(IJSRuntime jsRuntime)

Parameters

jsRuntime IJSRuntime

The JavaScript runtime for interop operations.

Remarks

Initializes a new instance of the SessionStorageService class.

Methods

ClearAsync()

Clears all items from sessionStorage.

public ValueTask ClearAsync()

Returns

ValueTask

A ValueTask representing the asynchronous operation.

ContainKeyAsync(string)

Checks if a key exists in sessionStorage.

public ValueTask<bool> ContainKeyAsync(string key)

Parameters

key string

The key to check for existence.

Returns

ValueTask<bool>

A ValueTask<TResult> representing the asynchronous operation, containing true if the key exists, otherwise false.

GetItemAsStringAsync(string)

Gets an item from sessionStorage as a raw string.

public ValueTask<string?> GetItemAsStringAsync(string key)

Parameters

key string

The key of the item to retrieve.

Returns

ValueTask<string>

A ValueTask<TResult> representing the asynchronous operation, containing the stored string value or null if not found.

GetItemAsync<T>(string)

Gets an item from sessionStorage and deserializes it from JSON.

public ValueTask<T?> GetItemAsync<T>(string key)

Parameters

key string

The key of the item to retrieve.

Returns

ValueTask<T>

A ValueTask<TResult> representing the asynchronous operation, containing the deserialized value or default if not found.

Type Parameters

T

The type to deserialize the stored value to.

KeyAsync(int)

Gets the key at the specified index in sessionStorage.

public ValueTask<string?> KeyAsync(int index)

Parameters

index int

The zero-based index of the key to retrieve.

Returns

ValueTask<string>

A ValueTask<TResult> representing the asynchronous operation, containing the key at the specified index or null if the index is out of range.

LengthAsync()

Gets the number of items stored in sessionStorage.

public ValueTask<int> LengthAsync()

Returns

ValueTask<int>

A ValueTask<TResult> representing the asynchronous operation, containing the number of stored items.

RemoveItemAsync(string)

Removes an item from sessionStorage.

public ValueTask RemoveItemAsync(string key)

Parameters

key string

The key of the item to remove.

Returns

ValueTask

A ValueTask representing the asynchronous operation.

SetItemAsStringAsync(string, string)

Sets an item in sessionStorage as a raw string.

public ValueTask SetItemAsStringAsync(string key, string value)

Parameters

key string

The key of the item to set.

value string

The string value to store.

Returns

ValueTask

A ValueTask representing the asynchronous operation.

SetItemAsync<T>(string, T)

Sets an item in sessionStorage by serializing the value to JSON.

public ValueTask SetItemAsync<T>(string key, T value)

Parameters

key string

The key of the item to set.

value T

The value to serialize and store.

Returns

ValueTask

A ValueTask representing the asynchronous operation.

Type Parameters

T

The type of the value to store.