Blazor.Extensions.Storage 0.4.0

HTML 5 Storage API implementation for ASP.NET Core Blazor.

This package is considered a SemVer 2.0.0 package as it has a package dependency on SemVer 2.0.0 package(s).
This package will only be available to download with SemVer 2.0.0 compatible NuGet clients, such as Visual Studio 2017 (version 15.3) and above or NuGet client 4.3.0 and above. Read more
Install-Package Blazor.Extensions.Storage -Version 0.4.0
dotnet add package Blazor.Extensions.Storage --version 0.4.0
<PackageReference Include="Blazor.Extensions.Storage" Version="0.4.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Blazor.Extensions.Storage --version 0.4.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.

Setup

The following snippet shows how to setup the storage wrapper by registering it for dependency injection in the Startup.cs of the application.

public void ConfigureServices(IServiceCollection services)
{
    // Add Blazor.Extensions.Storage
    // Both SessionStorage and LocalStorage are registered
    services.AddStorage();
}

Usage

The following snippet shows how to consume the storage API in a Blazor component.

@inject SessionStorage sessionStorage
@inject LocalStorage localStorage

@functions {
  protected override async Task OnInitializedAsync()
  {
        var key = "forecasts";
        await sessionStorage.SetItem<WeatherForecast[]>(key, forecasts);
        await localStorage.SetItem<WeatherForecast[]>(key, forecasts);
        var fromSession = await sessionStorage.GetItem<WeatherForecast[]>(key);
        var fromLocal = await localStorage.GetItem<WeatherForecast[]>(key);
  }
}

If you want to consume it outside of a cshtml based component, then you can use the Inject attribute to inject it into the class.

[Inject]
protected SessionStorage sessionStorage;

[Inject]
protected LocalStorage localStorage;

public Task LogSomething()
{
        var key = "forecasts";
        await sessionStorage.SetItem<WeatherForecast[]>(key, forecasts);
        await localStorage.SetItem<WeatherForecast[]>(key, forecasts);
        var fromSession = await sessionStorage.GetItem<WeatherForecast[]>(key);
        var fromLocal = await localStorage.GetItem<WeatherForecast[]>(key);
}

Contributions and feedback

Please feel free to use the component, open issues, fix bugs or provide feedback.

Contributors

The following people are the maintainers of the Blazor Extensions projects:

Setup

The following snippet shows how to setup the storage wrapper by registering it for dependency injection in the Startup.cs of the application.

public void ConfigureServices(IServiceCollection services)
{
    // Add Blazor.Extensions.Storage
    // Both SessionStorage and LocalStorage are registered
    services.AddStorage();
}

Usage

The following snippet shows how to consume the storage API in a Blazor component.

@inject SessionStorage sessionStorage
@inject LocalStorage localStorage

@functions {
  protected override async Task OnInitializedAsync()
  {
        var key = "forecasts";
        await sessionStorage.SetItem<WeatherForecast[]>(key, forecasts);
        await localStorage.SetItem<WeatherForecast[]>(key, forecasts);
        var fromSession = await sessionStorage.GetItem<WeatherForecast[]>(key);
        var fromLocal = await localStorage.GetItem<WeatherForecast[]>(key);
  }
}

If you want to consume it outside of a cshtml based component, then you can use the Inject attribute to inject it into the class.

[Inject]
protected SessionStorage sessionStorage;

[Inject]
protected LocalStorage localStorage;

public Task LogSomething()
{
        var key = "forecasts";
        await sessionStorage.SetItem<WeatherForecast[]>(key, forecasts);
        await localStorage.SetItem<WeatherForecast[]>(key, forecasts);
        var fromSession = await sessionStorage.GetItem<WeatherForecast[]>(key);
        var fromLocal = await localStorage.GetItem<WeatherForecast[]>(key);
}

Contributions and feedback

Please feel free to use the component, open issues, fix bugs or provide feedback.

Contributors

The following people are the maintainers of the Blazor Extensions projects:

Showing the top 1 GitHub repositories that depend on Blazor.Extensions.Storage:

Repository Stars
PKISharp/ACMESharpCore
An ACME v2 client library for .NET Standard (Let's Encrypt)

Version History

Version Downloads Last updated
0.4.0 192 9/9/2019
0.3.0 445 8/16/2019
0.2.1 499 7/31/2019
0.2.0 105 7/28/2019
0.1.9 683 7/2/2019
0.1.8 1,266 5/1/2019
0.1.7 4,306 11/26/2018
0.1.6 1,426 10/14/2018
0.1.5 596 7/29/2018
0.1.4 187 7/27/2018
0.1.3 178 7/27/2018
0.1.2 203 7/26/2018
0.1.1 337 6/8/2018
0.1.0 284 5/12/2018