https://github.com/manusoft/manuhub-blazor-utilities
WasmBrowserStorage 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.
https://github.com/manusoft/manuhub-blazor-utilities
blazor blazor-webassembly cookiestorage localstorage sessionstorage wasm
Last synced: 4 months ago
JSON representation
WasmBrowserStorage 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.
- Host: GitHub
- URL: https://github.com/manusoft/manuhub-blazor-utilities
- Owner: manusoft
- License: mit
- Created: 2025-01-24T20:35:33.000Z (over 1 year ago)
- Default Branch: master
- Last Pushed: 2025-03-15T17:20:08.000Z (about 1 year ago)
- Last Synced: 2025-06-18T08:51:33.631Z (12 months ago)
- Topics: blazor, blazor-webassembly, cookiestorage, localstorage, sessionstorage, wasm
- Language: CSS
- Homepage: https://www.nuget.org/packages/BrowserStorage.Wasm
- Size: 759 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.txt
Awesome Lists containing this project
README
  
# 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`).
### ICookieStore Example
```csharp
// 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", expires: 24); // Set cookie with expiration
var user = await _cookieStore.GetAsync("user"); // Get cookie
await _cookieStore.DeleteAsync("user"); // Remove cookie
}
}
```
### ISessionStore Example
```csharp
// 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("sessionData"); // Get session data
await _sessionStore.RemoveItemAsync("sessionData"); // Remove session data
}
}
```
### ILocalStore Example
```csharp
// 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("persistentData"); // Get persistent data
await _localStore.RemoveItemAsync("persistentData"); // Remove persistent data
}
}
```
### Register services in your Blazor app:
```csharp
builder.Services.AddWasmBrowserStorage();
```
## 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](LICENSE.txt) file for details.