Janar.BlazorStorage
2.0.5
dotnet add package Janar.BlazorStorage --version 2.0.5
NuGet\Install-Package Janar.BlazorStorage -Version 2.0.5
<PackageReference Include="Janar.BlazorStorage" Version="2.0.5" />
<PackageVersion Include="Janar.BlazorStorage" Version="2.0.5" />
<PackageReference Include="Janar.BlazorStorage" />
paket add Janar.BlazorStorage --version 2.0.5
#r "nuget: Janar.BlazorStorage, 2.0.5"
#:package Janar.BlazorStorage@2.0.5
#addin nuget:?package=Janar.BlazorStorage&version=2.0.5
#tool nuget:?package=Janar.BlazorStorage&version=2.0.5
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:
🚀 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.
Thank you for using Janar.BlazorStorage!
| Product | Versions 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. |
-
net10.0
- Microsoft.AspNetCore.Cryptography.Internal (>= 10.0.8)
- Microsoft.AspNetCore.DataProtection (>= 10.0.8)
- Microsoft.AspNetCore.DataProtection.Abstractions (>= 10.0.8)
- Microsoft.Extensions.Logging.Abstractions (>= 10.0.8)
- Microsoft.Extensions.Options (>= 10.0.8)
- Microsoft.JSInterop (>= 10.0.8)
- System.Security.Cryptography.Xml (>= 10.0.8)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
