BrowserStorage.Wasm
1.0.2
dotnet add package BrowserStorage.Wasm --version 1.0.2
NuGet\Install-Package BrowserStorage.Wasm -Version 1.0.2
<PackageReference Include="BrowserStorage.Wasm" Version="1.0.2" />
paket add BrowserStorage.Wasm --version 1.0.2
#r "nuget: BrowserStorage.Wasm, 1.0.2"
// Install BrowserStorage.Wasm as a Cake Addin #addin nuget:?package=BrowserStorage.Wasm&version=1.0.2 // Install BrowserStorage.Wasm as a Cake Tool #tool nuget:?package=BrowserStorage.Wasm&version=1.0.2
BrowserStorage.Wasm
BrowserStorage.Wasm
is a Razor library for managing browser storage in WebAssembly (WASM) applications. This package includes interfaces for managing data across cookies, session, and local storage with asynchronous methods. It is recommended to access these storage options only via the provided interfaces.
Features
- ICookieStore: Interface for managing data in browser cookies with async operations.
- ISessionStore: Interface for managing session data that is cleared when the session ends.
- ILocalStore: Interface for managing persistent data in local storage.
Usage
To use the package, make sure to access storage via the provided interfaces (ICookieStore
, ISessionStore
, ILocalStore
).
Register services in your Blazor app:
builder.Services.AddWasmBrowserStorage();
ICookieStore Example
// Inject ICookieStore in your Razor component or service
public class ExampleService
{
private readonly ICookieStore _cookieStore;
public ExampleService(ICookieStore cookieStore)
{
_cookieStore = cookieStore;
}
public async Task ManageCookies()
{
await _cookieStore.SetAsync("user", "JohnDoe", 1); // Set cookie with expiration
var user = await _cookieStore.GetAsync<string>("user"); // Get cookie
await _cookieStore.DeleteAsync("user"); // Remove cookie
}
}
ISessionStore Example
// Inject ISessionStore in your Razor component or service
public class ExampleService
{
private readonly ISessionStore _sessionStore;
public ExampleService(ISessionStore sessionStore)
{
_sessionStore = sessionStore;
}
public async Task ManageSession()
{
await _sessionStore.SetAsync("sessionData", "value"); // Store data for session
var sessionData = await _sessionStore.GetAsync<string>("sessionData"); // Get session data
await _sessionStore.DeleteAsync("sessionData"); // Remove session data
}
}
ILocalStore Example
// Inject ILocalStore in your Razor component or service
public class ExampleService
{
private readonly ILocalStore _localStore;
public ExampleService(ILocalStore localStore)
{
_localStore = localStore;
}
public async Task ManageLocalStorage()
{
await _localStore.SetAsync("persistentData", "value"); // Store data persistently
var persistentData = await _localStore.GetAsync<string>("persistentData"); // Get persistent data
await _localStore.DeleteAsync("persistentData"); // Remove persistent data
}
}
Contributing
We welcome contributions to the project! If you'd like to contribute, please fork the repository and submit a pull request with your changes.
License
This project is licensed under the MIT License - see the LICENSE file for details.
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 is compatible. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. |
-
net8.0
- Microsoft.AspNetCore.Components.Web (>= 8.0.12)
-
net9.0
- Microsoft.AspNetCore.Components.Web (>= 9.0.1)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.