BrowserStorage.Wasm is a Razor library designed for browser storage management in WebAssembly (WASM) applications. This package provides easy-to-use implementations for managing data in the browser's cookie, session, and local storage.
$ dotnet add package 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.
To use the package, make sure to access storage via the provided interfaces (ICookieStore, ISessionStore, ILocalStore).
builder.Services.AddWasmBrowserStorage();
// 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
}
}
// 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
}
}
// 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
}
}
We welcome contributions to the project! If you'd like to contribute, please fork the repository and submit a pull request with your changes.
This project is licensed under the MIT License - see the LICENSE file for details.