NetcodeHub.Packages.Extensions.LocalStorage
1.0.0
dotnet add package NetcodeHub.Packages.Extensions.LocalStorage --version 1.0.0
NuGet\Install-Package NetcodeHub.Packages.Extensions.LocalStorage -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="NetcodeHub.Packages.Extensions.LocalStorage" Version="1.0.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add NetcodeHub.Packages.Extensions.LocalStorage --version 1.0.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: NetcodeHub.Packages.Extensions.LocalStorage, 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.
// Install NetcodeHub.Packages.Extensions.LocalStorage as a Cake Addin #addin nuget:?package=NetcodeHub.Packages.Extensions.LocalStorage&version=1.0.0 // Install NetcodeHub.Packages.Extensions.LocalStorage as a Cake Tool #tool nuget:?package=NetcodeHub.Packages.Extensions.LocalStorage&version=1.0.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
Install the package
NetcodeHub.Packages.Extensions.LocalStorage
Register package service
builder.Services.AddNetcodeHubLocalStorageService();
inject package and in the import.razor file
@inject ILocalStorageService localStorageService
Use the package in razor components
Without Encryption
GetItemAsStringAsync(string key) : This interface gets and returns item from the browser's local storage in the form of string data type.
SaveAsStringAsync(string key, string content) : This interface sets or saves item in the form of string to the browser's local storage.
GetItemAsModelAsync<T>(string key) : This interface converts T Value being specified to string content before saving to browser's local storage.
DeleteItemAsync(string key) : This interface deletes or removes item from the local storage with the key provided.
AddItemToListAsync<T>(string key, T content) : This interface creates T List of items, add T Value (spcified) and save to browser's local storage.
GetItemListAsync<T>(string key) : This interface returns T List of items specified from browser's local storage.
GetItemsCountAsync<T>(string key) : This interface returns the count of T List of item from the browser's local storage.
With Encryption
AddItemToEncryptedListAsync<T>(string key, T content) : This interface creates T List of items, add T Value (specified), encrypt and save to browser's local storage.
GetEncryptedItemAsStringAsync(string key) : This interface gets, decrypts and return item from the browser's local storage in the form of string data type.
GetEncryptedItemsCountAsync<T>(string key) : This interface decrypts and return the count of T List of item from the browser's local storage.
GetEncryptedItemListAsync<T>(string key) : This interface decrypts and return T List of items specified from browser's local storage.
GetEncryptedItemAsModelAsync<T>(string key) : This interface encrypts and convert T Value being specified to string content before saving to browser's local storage.
SaveEncryptedItemAsModelAsync<T>(string key, T content) : This interface encrypts and convert T Value being specified to string content before saving to browser's local storage.
SaveAsEncryptedStringAsync(string key, string content) : This interface encrypts and save item in the form of string to the browser's local storage.
EXAMPLE
@page "/"
@rendermode InteractiveServer
@using NetcodeHub.Packages.Extensions.LocalStorage
@using NetcodeHub.Packages.Extensions.SessionStorage
@inject ILocalStorageService localStorageService
@inject ISessionStorageService sessionStorageService
<h4>Set and Get String</h4>
<h2>Content: @Content</h2>
<button class="btn btn-primary m-2" @onclick="SetString">Set String </button>
<button class="btn btn-primary m-2" @onclick="GetString">Get String </button>
<div class="m-2 p-3">
Id: @entity.Id <br />
Name: @entity.Name <br />
Email: @entity.Email <br />
</div>
<button class="btn btn-primary m-2" @onclick="SetModel">Set Model </button>
<button class="btn btn-primary m-2" @onclick="GetModel">Get Model </button>
<div class="m-2 p-2">
@if (Entities != null)
{
@foreach (var i in Entities)
{
<div class="m-2 p-3">
Id: @i.Id <br />
Name: @i.Name <br />
Email: @i.Email <br />
</div>
}
}
</div>
<button class="btn btn-primary m-2" @onclick="SetListModel">Set List Model </button>
<button class="btn btn-primary m-2" @onclick="GetListModel">Get List Model </button>
Count: [@Count]
<button class="btn btn-primary m-2" @onclick="GetCount">Get Count</button>
<button class="btn btn-primary m-2" @onclick="AddItemToLocal">Add Item To Local</button>
@code {
string? Content;
Local Storage Session Storage
Get and Set String as Unprotected
async Task SetString() => await localStorageService.SaveAsEncryptedStringAsync("key", "Netcode-Hub");
async Task GetString() => Content = (await localStorageService.GetEncryptedItemAsStringAsync("key"));
async Task SetString() => await sessionStorageService.SaveAsEncryptedStringAsync("key", "Netcode-Hub");
async Task GetString() => Content = (await sessionStorageService.GetEncryptedItemAsStringAsync("key"));
Get and Set String as Protected
async Task SetString() => await localStorageService.SaveAsEncryptedStringAsync("key", "Netcode-Hub");
async Task GetString() => Content = (await localStorageService.GetEncryptedItemAsStringAsync("key"));
async Task SetString() => await sessionStorageService.SaveAsEncryptedStringAsync("key", "Netcode-Hub");
async Task GetString() => Content = (await sessionStorageService.GetEncryptedItemAsStringAsync("key"));
Entity entity = new();
Entity entity1 = new();
Get and Set Model as Unprotected
async Task SetModel()
{
entity1.Id = 1;
entity1.Name = "Netcode-Hub";
entity1.Email = "NetcodeHub@gmail.com";
await localStorageService.SaveItemAsModelAsync<Entity>("key", entity1);
}
async Task GetModel() => entity = await localStorageService.GetItemAsModelAsync<Entity>("key");
async Task SetModel()
{
entity1.Id = 1;
entity1.Name = "Netcode-Hub";
entity1.Email = "NetcodeHub@gmail.com";
await sessionStorageService.SaveItemAsModelAsync<Entity>("key", entity1);
}
async Task GetModel() => entity = await sessionStorageService.GetItemAsModelAsync<Entity>("key");
Get and Set Model as Protected
async Task SetModel()
{
entity1.Id = 1;
entity1.Name = "Netcode-Hub";
entity1.Email = "NetcodeHub@gmail.com";
await localStorageService.SaveEncryptedItemAsModelAsync<Entity>("key", entity1);
}
async Task GetModel() => entity = await localStorageService.GetEncryptedItemAsModelAsync<Entity>("key");
async Task SetModel()
{
entity1.Id = 1;
entity1.Name = "Netcode-Hub";
entity1.Email = "NetcodeHub@gmail.com";
await sessionStorageService.SaveEncryptedItemAsModelAsync<Entity>("key", entity1);
}
async Task GetModel() => entity = await sessionStorageService.GetEncryptedItemAsModelAsync<Entity>("key");
List<Entity> Entities = [];
Get and Set List<T> as Unprotected
async Task SetListModel()
{
entity1.Id = 1;
entity1.Name = "Netcode-Hub";
entity1.Email = "NetcodeHub@gmail.com";
await localStorageService.AddItemToListAsync<Entity>("key", entity1);
}
async Task GetListModel() => Entities = await localStorageService.GetItemListAsync<Entity>("key");
async Task SetListModel()
{
entity1.Id = 1;
entity1.Name = "Netcode-Hub";
entity1.Email = "NetcodeHub@gmail.com";
await sessionStorageService.AddItemToListAsync<Entity>("key", entity1);
}
async Task GetListModel() => Entities = await sessionStorageService.GetItemListAsync<Entity>("key");
Get and Set List<T> as Unprotected
async Task SetListModel()
{
entity1.Id = 1;
entity1.Name = "Netcode-Hub";
entity1.Email = "NetcodeHub@gmail.com";
await localStorageService.AddItemToEncryptedListAsync<Entity>("key", entity1);
}
async Task GetListModel() => Entities = await localStorageService.GetEncryptedItemListAsync<Entity>("key");
async Task SetListModel()
{
entity1.Id = 1;
entity1.Name = "Netcode-Hub";
entity1.Email = "NetcodeHub@gmail.com";
await sessionStorageService.AddItemToEncryptedListAsync<Entity>("key", entity1);
}
async Task GetListModel() => Entities = await sessionStorageService.GetEncryptedItemListAsync<Entity>("key");
async Task AddItemToLocal()
{
entity1.Id = 1;
entity1.Name = "Netcode-Hub";
entity1.Email = "NetcodeHub@gmail.com";
await localStorageService.AddItemToListAsync<Entity>("key", entity1);
}
int Count;
async Task GetCount() => Count = await localStorageService.GetItemsCountAsync<Entity>("key");
async Task GetEncryptedCount() => Count = await localStorageService.GetEncryptedItemsCountAsync<Entity>("key");
async Task GetSessionCount() => Count = await sessionStorageService.GetItemsCountAsync<Entity>("key");
async Task DeleteLocalItem() => await localStorageService.DeleteItemAsync("key");
async Task ClearLocalStorage() => await localStorageService.ClearAllItemsAsync();
async Task DeleteSessionItem() => await sessionStorageService.DeleteItemAsync("key");
async Task ClearSessionStorage() => await sessionStorageService.ClearAllItemsAsync();
public class Entity
{
public int Id { get; set; }
public string? Name { get; set; }
public string? Email { get; set; }
}
}
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. |
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
-
net8.0
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 8.0.1)
- Microsoft.JSInterop (>= 8.0.3)
NuGet packages (2)
Showing the top 2 NuGet packages that depend on NetcodeHub.Packages.Extensions.LocalStorage:
Package | Downloads |
---|---|
NetcodeHub.Packages.UI.Templates.Breeze
This User Interface Template allows developer to design classic look and feel web application interface by providing units such as Sidebar, Navigationbar, and Content templates designed with available third party libraries. |
|
NetcodeHub.Packages.Extensions.Localization
This package allows developer to integrate localization into Blazor applications with ease. |
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last updated |
---|---|---|
1.0.0 | 2,105 | 3/17/2024 |
This package is of its first kind, your suggestions may help improve the package