Janar.BlazorStorage 2.0.5

dotnet add package Janar.BlazorStorage --version 2.0.5
                    
NuGet\Install-Package Janar.BlazorStorage -Version 2.0.5
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Janar.BlazorStorage" Version="2.0.5" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Janar.BlazorStorage" Version="2.0.5" />
                    
Directory.Packages.props
<PackageReference Include="Janar.BlazorStorage" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Janar.BlazorStorage --version 2.0.5
                    
#r "nuget: Janar.BlazorStorage, 2.0.5"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package Janar.BlazorStorage@2.0.5
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Janar.BlazorStorage&version=2.0.5
                    
Install as a Cake Addin
#tool nuget:?package=Janar.BlazorStorage&version=2.0.5
                    
Install as a Cake Tool

Janar BlazorStorage (LocalStorage + SessionStorage)

A lightweight, production-ready Blazor library for browser storage.

Supports:

  • LocalStorage
  • SessionStorage
  • Expiration support (like cookies)
  • Optional encryption (ASP.NET Data Protection)
  • Strongly typed APIs
  • Clean Dependency Injection

☕ Support

If you find this package helpful, please consider supporting me:

Buy Me A Coffee


🚀 Features

  • Simple dependency injection
  • Fully async API
  • LocalStorage support
  • SessionStorage support
  • Expiration per key
  • Optional encryption using ASP.NET Data Protection
  • Automatic JSON serialization/deserialization
  • Safe error handling
  • Production-ready structure

📦 Installation

Install via NuGet:

dotnet add package Janar.BlazorStorage

⚙️ Setup

Register services in Program.cs:

builder.Services.AddBlazorStorage(options =>
{
    options.UseEncryption = true; // optional
});

🧠 Usage

Inject services into Blazor components:

@inject ILocalStorageService LocalStorage
@inject ISessionStorageService SessionStorage

💾 LocalStorage Usage

Store data

await LocalStorage.SetItemAsync("user", user);

Store with expiration

await LocalStorage.SetItemAsync("user", user, TimeSpan.FromMinutes(30));

Get data

var user = await LocalStorage.GetItemAsync<User>("user");

Remove data

await LocalStorage.RemoveItemAsync("user");

Check existence

bool exists = await LocalStorage.ExistsAsync("user");

Clear all

await LocalStorage.ClearAsync();

📂 SessionStorage Usage

SessionStorage works exactly the same as LocalStorage:

await SessionStorage.SetItemAsync("token", token);
var token = await SessionStorage.GetItemAsync<string>("token");
await SessionStorage.RemoveItemAsync("token");
await SessionStorage.ClearAsync();

🔐 Encryption

When enabled:

options.UseEncryption = true;

All data stored in browser is automatically encrypted using ASP.NET Data Protection API.

No changes required in application code.


⏱ Expiration Support

You can set expiration per item:

await LocalStorage.SetItemAsync("key", value, TimeSpan.FromMinutes(10));

After expiration:

  • Data is automatically removed
  • GetItemAsync returns default value

🏗 Architecture

This library uses:

  • JavaScript Interop for browser storage
  • JSON serialization for type safety
  • ASP.NET Data Protection for encryption
  • Dependency Injection for clean usage

🧩 Supported Data Types

  • Primitive types (string, int, bool, etc.)
  • Complex objects (POCO classes)
  • Lists and collections
  • Custom models

⚠️ Notes

  • Works only in browser environment
  • Blazor WebAssembly fully supported
  • Blazor Server supported via JS interop
  • Encryption requires Microsoft.AspNetCore.DataProtection
  • Keys are case-sensitive

📦 Versioning

Change Type Version
Feature 2.0.0
Bug Fix 2.0.3
Breaking 2.0.4

📄 License

MIT License


❤️ Author

Built with love for Blazor developers.


Buy Me a Coffee

Thank you for using Janar.BlazorStorage!

Product Compatible and additional computed target framework versions.
.NET net10.0 is compatible.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
2.0.5 128 5/29/2026
2.0.4 119 4/19/2026
2.0.3 116 4/19/2026
2.0.2 108 4/19/2026
2.0.1 112 4/19/2026
2.0.0 129 4/13/2026