Skip to content

Commit

Permalink
Fix readme
Browse files Browse the repository at this point in the history
  • Loading branch information
galvesribeiro committed Oct 30, 2019
1 parent 3b1a3d9 commit 3d3e3d8
Showing 1 changed file with 77 additions and 77 deletions.
154 changes: 77 additions & 77 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,77 +1,77 @@
[![Build status](https://dotnet-ci.visualstudio.com/DotnetCI/_apis/build/status/Blazor-Extensions-Storage-CI?branch=master)](https://dotnet-ci.visualstudio.com/DotnetCI/_build/latest?definitionId=12&branch=master)
[![Package Version](https://img.shields.io/nuget/v/Blazor.Extensions.Storage.svg)](https://www.nuget.org/packages/Blazor.Extensions.Storage)
[![NuGet Downloads](https://img.shields.io/nuget/dt/Blazor.Extensions.Storage.svg)](https://www.nuget.org/packages/Blazor.Extensions.Storage)
[![License](https://img.shields.io/github/license/BlazorExtensions/Storage.svg)](https://github.com/BlazorExtensions/Storage/blob/master/LICENSE)

# Blazor Extensions

Blazor Extensions are a set of packages with the goal of adding useful things to [Blazor](https://blazor.net).

# Blazor Extensions Storage

This package wraps [HTML5 Storage](https://developer.mozilla.org/en-US/docs/Web/API/Storage) APIs. Both Session and Local storage types are supported.

# Sample configuration

## Setup

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

```c#
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.

```c#
@inject SessionStorage sessionStorage
@inject LocalStorage localStorage

@functions {
protected override async Task OnInitAsync()
{
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.

```c#
[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:

- [Attila Hajdrik](https://github.com/attilah)
- [Gutemberg Ribiero](https://github.com/galvesribeiro)
[![Build](https://github.com/BlazorExtensions/Storage/workflows/CI/badge.svg)](https://github.com/BlazorExtensions/Storage/actions)
[![Package Version](https://img.shields.io/nuget/v/Blazor.Extensions.Storage.svg)](https://www.nuget.org/packages/Blazor.Extensions.Storage)
[![NuGet Downloads](https://img.shields.io/nuget/dt/Blazor.Extensions.Storage.svg)](https://www.nuget.org/packages/Blazor.Extensions.Storage)
[![License](https://img.shields.io/github/license/BlazorExtensions/Storage.svg)](https://github.com/BlazorExtensions/Storage/blob/master/LICENSE)

# Blazor Extensions

Blazor Extensions are a set of packages with the goal of adding useful things to [Blazor](https://blazor.net).

# Blazor Extensions Storage

This package wraps [HTML5 Storage](https://developer.mozilla.org/en-US/docs/Web/API/Storage) APIs. Both Session and Local storage types are supported.

# Sample configuration

## Setup

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

```c#
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.

```c#
@inject SessionStorage sessionStorage
@inject LocalStorage localStorage

@functions {
protected override async Task OnInitAsync()
{
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.

```c#
[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:

- [Attila Hajdrik](https://github.com/attilah)
- [Gutemberg Ribiero](https://github.com/galvesribeiro)

0 comments on commit 3d3e3d8

Please sign in to comment.