AvaloniaWASM.Storage 1.0.0

dotnet add package AvaloniaWASM.Storage --version 1.0.0
                    
NuGet\Install-Package AvaloniaWASM.Storage -Version 1.0.0
                    
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="AvaloniaWASM.Storage" Version="1.0.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="AvaloniaWASM.Storage" Version="1.0.0" />
                    
Directory.Packages.props
<PackageReference Include="AvaloniaWASM.Storage" />
                    
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 AvaloniaWASM.Storage --version 1.0.0
                    
#r "nuget: AvaloniaWASM.Storage, 1.0.0"
                    
#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.
#addin nuget:?package=AvaloniaWASM.Storage&version=1.0.0
                    
Install as a Cake Addin
#tool nuget:?package=AvaloniaWASM.Storage&version=1.0.0
                    
Install as a Cake Tool

AvaloniaWASM.Storage

This library provides a simple way to use browser storage in AvaloniaUI applications. It supports both local, session storage as well as IndexedDB, allowing you to store key-value pairs that persist across sessions or only for the duration of the page load. The IndexedDB support is useful for storing larger files or structured data.

Sample Application

Session / Local Storage IndexedDB
image image

How to Use

  1. Install the Nuget Package (Both in the base and startup projects).

  2. Add the required JSScript loading to your crossplatform project (File : xxxx.csproj).


	# Option  1
	# Direct Reference, Add the following section to your App.cs file or wherever you initialize your application.

	if (OperatingSystem.IsBrowser())
        {
            await JSHost.ImportAsync("FuncLocalStorage", "/js/FuncLocalStorage.js");
            await JSHost.ImportAsync("FuncSessionStorage", "/js/FuncSessionStorage.js");
			await JSHost.ImportAsync("FuncIndexedDbFile", "/js/FuncIndexedDbFile.js");

        }

	..........

	# Option  2
	# For Dependency Injection, inject the services in your `App.cs` file or wherever you configure your services.

	services.AddBrowserStorage();

  1. Use the LocalStorage and SessionStorage classes to store and retrieve data in your AvaloniaUI application.
	using AvaloniaWASM.Storage;

	.........

	# Initialize the storage services in your class or view model, if not dependecy Injection.
	private SessionStorageService _sessionStorageService = new SessionStorageService();
	private LocalStorageService _localStorageService = new LocalStorageService();

	..........

	# Session Storage Example
	await _sessionStorageService.SetItemAsync("Session_Text", ValueToSetSessionStorage);
	ValueFromSessionStorage = await _sessionStorageService.GetItemAsync("Session_Text");

	...........
	# Local Storage Example
	await _localStorageService.SetItemAsync("Local_Text", ValueToSetLocalStorage);
	ValueFromLocalStorage = await _localStorageService.GetItemAsync("Local_Text");

	...........
	# IndexedDB Example
	await IndexedDbFileService.SaveFileAsync(dbName, storeName, fileName, _fileContent, "text/plain");
	var filefromDB = await IndexedDbFileService.LoadFileAsBase64Async(dbName, storeName, fileName);
  1. Build startup project to ensure the JavaScript files are copied to the correct location (./wwwroot/js/**).
Product Compatible and additional computed target framework versions.
.NET 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.  net10.0 was computed.  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
1.0.0 135 6/2/2025