All Projects → Blazored → Sessionstorage

Blazored / Sessionstorage

Licence: mit
A library to provide access to session storage in Blazor applications

Programming Languages

csharp
926 projects

Projects that are alternatives of or similar to Sessionstorage

Fluentvalidation
A library for using FluentValidation with Blazor
Stars: ✭ 184 (+39.39%)
Mutual labels:  hacktoberfest, nuget
32feet
Personal Area Networking for .NET
Stars: ✭ 395 (+199.24%)
Mutual labels:  hacktoberfest, nuget
Typeahead
Typeahead control for Blazor applications
Stars: ✭ 226 (+71.21%)
Mutual labels:  hacktoberfest, nuget
Msbuild.sdk.sqlproj
An MSBuild SDK that provides similar functionality to SQL Server Data Tools (.sqlproj) projects
Stars: ✭ 142 (+7.58%)
Mutual labels:  hacktoberfest, nuget
Quartznet
Quartz Enterprise Scheduler .NET
Stars: ✭ 4,825 (+3555.3%)
Mutual labels:  hacktoberfest, nuget
Mond
A scripting language for .NET Core
Stars: ✭ 237 (+79.55%)
Mutual labels:  hacktoberfest, nuget
Toast
A JavaScript free toast library for Blazor and Razor Component applications
Stars: ✭ 296 (+124.24%)
Mutual labels:  hacktoberfest, nuget
Modal
A powerful and customizable modal implementation for Blazor applications.
Stars: ✭ 406 (+207.58%)
Mutual labels:  hacktoberfest, nuget
Localstorage
A library to provide access to local storage in Blazor applications
Stars: ✭ 425 (+221.97%)
Mutual labels:  hacktoberfest, nuget
Strongbox
Strongbox is an artifact repository manager.
Stars: ✭ 412 (+212.12%)
Mutual labels:  hacktoberfest, nuget
Across Tabs
Easy communication between cross-origin browser tabs. Simplified "CORS"ing!
Stars: ✭ 1,575 (+1093.18%)
Mutual labels:  hacktoberfest, sessionstorage
Menu
A JavaScript free menu library for Blazor and Razor Components applications.
Stars: ✭ 118 (-10.61%)
Mutual labels:  hacktoberfest, nuget
Colore
A powerful C# library for Razer Chroma's SDK
Stars: ✭ 121 (-8.33%)
Mutual labels:  hacktoberfest, nuget
Python Docs Es
Spanish translation of the Python documentation.
Stars: ✭ 131 (-0.76%)
Mutual labels:  hacktoberfest
Flask simplelogin
Simple Login - Login Extension for Flask - maintainer @cuducos
Stars: ✭ 133 (+0.76%)
Mutual labels:  hacktoberfest
Silverstripe Userforms
UserForms module provides a visual form builder for the SilverStripe CMS. No coding required to build forms such as contact pages.
Stars: ✭ 132 (+0%)
Mutual labels:  hacktoberfest
Remoting
Jenkins Remoting module
Stars: ✭ 132 (+0%)
Mutual labels:  hacktoberfest
Manual Node
📗 📒 (PT-BR Tradução) 2020 Edition - Tradução por Christy e Vinicius Dias (https://github.com/ViniciusmDias).
Stars: ✭ 134 (+1.52%)
Mutual labels:  hacktoberfest
Flutter hooks
React hooks for Flutter. Hooks are a new kind of object that manages a Widget life-cycles. They are used to increase code sharing between widgets and as a complete replacement for StatefulWidget.
Stars: ✭ 1,973 (+1394.7%)
Mutual labels:  hacktoberfest
Terasologylauncher
Terasology Launcher is the official launcher for the open source game Terasology.
Stars: ✭ 132 (+0%)
Mutual labels:  hacktoberfest

Blazored SessionStorage

A library to provide access to session storage in Blazor applications

Build Status

Nuget

Installing

You can install from NuGet using the following command:

Install-Package Blazored.SessionStorage

Or via the Visual Studio package manager.

Setup

You will need to register the session storage services with the service collection in your Startup.cs file in Blazor Server.

public void ConfigureServices(IServiceCollection services)
{
    services.AddBlazoredSessionStorage();
}

Or in your Program.cs file in Blazor WebAssembly.

public static async Task Main(string[] args)
{
    var builder = WebAssemblyHostBuilder.CreateDefault(args);
    builder.RootComponents.Add<App>("app");

    builder.Services.AddBlazoredSessionStorage();

    await builder.Build().RunAsync();
}

Configuration

The session storage provides options that can be modified by you at registration in your Startup.cs file in Blazor Server.

public void ConfigureServices(IServiceCollection services)
{
    services.AddBlazoredSessionStorage(config =>
        config.JsonSerializerOptions.WriteIndented = true);
}

Or in your Program.cs file in Blazor WebAssembly.

public static async Task Main(string[] args)
{
    var builder = WebAssemblyHostBuilder.CreateDefault(args);
    builder.RootComponents.Add<App>("app");

    builder.Services.AddBlazoredSessionStorage(config =>
        config.JsonSerializerOptions.WriteIndented = true);

    await builder.Build().RunAsync();
}

Usage (Blazor WebAssembly)

To use Blazored.SessionStorage in Blazor WebAssembly, inject the ISessionStorageService per the example below.

@inject Blazored.SessionStorage.ISessionStorageService sessionStorage

@code {

    protected override async Task OnInitializedAsync()
    {
        await sessionStorage.SetItemAsync("name", "John Smith");
        var name = await sessionStorage.GetItemAsync<string>("name");
    }

}

With Blazor WebAssembly you also have the option of a synchronous API, if your use case requires it. You can swap the ISessionStorageService for ISyncSessionStorageService which allows you to avoid use of async/await. For either interface, the method names are the same.

@inject Blazored.SessionStorage.ISyncSessionStorageService sessionStorage

@code {

    protected override void OnInitialized()
    {
        sessionStorage.SetItem("name", "John Smith");
        var name = sessionStorage.GetItem<string>("name");
    }

}

Usage (Blazor Server)

NOTE: Due to pre-rendering in Blazor Server you can't perform any JS interop until the OnAfterRender lifecycle method.

@inject Blazored.SessionStorage.ISessionStorageService sessionStorage

@code {

    protected override async Task OnAfterRenderAsync(bool firstRender)
    {
        await sessionStorage.SetItemAsync("name", "John Smith");
        var name = await sessionStorage.GetItemAsync<string>("name");
    }

}

The APIs available are:

  • asynchronous via ISessionStorageService:

    • SetItemAsync()
    • GetItemAsync()
    • RemoveItemAsync()
    • ClearAsync()
    • LengthAsync()
    • KeyAsync()
    • ContainsKeyAsync()
  • synchronous via ISyncSessionStorageService (Synchronous methods are only available in Blazor WebAssembly):

    • SetItem()
    • GetItem()
    • RemoveItem()
    • Clear()
    • Length()
    • Key()
    • ContainsKey()

Note: Blazored.SessionStorage methods will handle the serialisation and de-serialisation of the data for you.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].