|
1 |
| -[](https://dotnet-ci.visualstudio.com/DotnetCI/_build/latest?definitionId=12&branch=master) |
2 |
| -[](https://www.nuget.org/packages/Blazor.Extensions.Storage) |
3 |
| -[](https://www.nuget.org/packages/Blazor.Extensions.Storage) |
4 |
| -[](https://github.com/BlazorExtensions/Storage/blob/master/LICENSE) |
5 |
| - |
6 |
| -# Blazor Extensions |
7 |
| - |
8 |
| -Blazor Extensions are a set of packages with the goal of adding useful things to [Blazor](https://blazor.net). |
9 |
| - |
10 |
| -# Blazor Extensions Storage |
11 |
| - |
12 |
| -This package wraps [HTML5 Storage](https://developer.mozilla.org/en-US/docs/Web/API/Storage) APIs. Both Session and Local storage types are supported. |
13 |
| - |
14 |
| -# Sample configuration |
15 |
| - |
16 |
| -## Setup |
17 |
| - |
18 |
| -The following snippet shows how to setup the storage wrapper by registering it for dependency injection in the ```Startup.cs``` of the application. |
19 |
| - |
20 |
| -```c# |
21 |
| -public void ConfigureServices(IServiceCollection services) |
22 |
| -{ |
23 |
| - // Add Blazor.Extensions.Storage |
24 |
| - // Both SessionStorage and LocalStorage are registered |
25 |
| - services.AddStorage(); |
26 |
| -} |
27 |
| -``` |
28 |
| - |
29 |
| -## Usage |
30 |
| - |
31 |
| -The following snippet shows how to consume the storage API in a Blazor component. |
32 |
| - |
33 |
| -```c# |
34 |
| -@inject SessionStorage sessionStorage |
35 |
| -@inject LocalStorage localStorage |
36 |
| - |
37 |
| -@functions { |
38 |
| - protected override async Task OnInitAsync() |
39 |
| - { |
40 |
| - var key = "forecasts"; |
41 |
| - await sessionStorage.SetItem<WeatherForecast[]>(key, forecasts); |
42 |
| - await localStorage.SetItem<WeatherForecast[]>(key, forecasts); |
43 |
| - var fromSession = await sessionStorage.GetItem<WeatherForecast[]>(key); |
44 |
| - var fromLocal = await localStorage.GetItem<WeatherForecast[]>(key); |
45 |
| - } |
46 |
| -} |
47 |
| -``` |
48 |
| - |
49 |
| -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. |
50 |
| - |
51 |
| -```c# |
52 |
| -[Inject] |
53 |
| -protected SessionStorage sessionStorage; |
54 |
| - |
55 |
| -[Inject] |
56 |
| -protected LocalStorage localStorage; |
57 |
| - |
58 |
| -public Task LogSomething() |
59 |
| -{ |
60 |
| - var key = "forecasts"; |
61 |
| - await sessionStorage.SetItem<WeatherForecast[]>(key, forecasts); |
62 |
| - await localStorage.SetItem<WeatherForecast[]>(key, forecasts); |
63 |
| - var fromSession = await sessionStorage.GetItem<WeatherForecast[]>(key); |
64 |
| - var fromLocal = await localStorage.GetItem<WeatherForecast[]>(key); |
65 |
| -} |
66 |
| -``` |
67 |
| - |
68 |
| -# Contributions and feedback |
69 |
| - |
70 |
| -Please feel free to use the component, open issues, fix bugs or provide feedback. |
71 |
| - |
72 |
| -# Contributors |
73 |
| - |
74 |
| -The following people are the maintainers of the Blazor Extensions projects: |
75 |
| - |
76 |
| -- [Attila Hajdrik](https://github.com/attilah) |
77 |
| -- [Gutemberg Ribiero](https://github.com/galvesribeiro) |
| 1 | +[](https://github.com/BlazorExtensions/Storage/actions) |
| 2 | +[](https://www.nuget.org/packages/Blazor.Extensions.Storage) |
| 3 | +[](https://www.nuget.org/packages/Blazor.Extensions.Storage) |
| 4 | +[](https://github.com/BlazorExtensions/Storage/blob/master/LICENSE) |
| 5 | + |
| 6 | +# Blazor Extensions |
| 7 | + |
| 8 | +Blazor Extensions are a set of packages with the goal of adding useful things to [Blazor](https://blazor.net). |
| 9 | + |
| 10 | +# Blazor Extensions Storage |
| 11 | + |
| 12 | +This package wraps [HTML5 Storage](https://developer.mozilla.org/en-US/docs/Web/API/Storage) APIs. Both Session and Local storage types are supported. |
| 13 | + |
| 14 | +# Sample configuration |
| 15 | + |
| 16 | +## Setup |
| 17 | + |
| 18 | +The following snippet shows how to setup the storage wrapper by registering it for dependency injection in the ```Startup.cs``` of the application. |
| 19 | + |
| 20 | +```c# |
| 21 | +public void ConfigureServices(IServiceCollection services) |
| 22 | +{ |
| 23 | + // Add Blazor.Extensions.Storage |
| 24 | + // Both SessionStorage and LocalStorage are registered |
| 25 | + services.AddStorage(); |
| 26 | +} |
| 27 | +``` |
| 28 | + |
| 29 | +## Usage |
| 30 | + |
| 31 | +The following snippet shows how to consume the storage API in a Blazor component. |
| 32 | + |
| 33 | +```c# |
| 34 | +@inject SessionStorage sessionStorage |
| 35 | +@inject LocalStorage localStorage |
| 36 | + |
| 37 | +@functions { |
| 38 | + protected override async Task OnInitAsync() |
| 39 | + { |
| 40 | + var key = "forecasts"; |
| 41 | + await sessionStorage.SetItem<WeatherForecast[]>(key, forecasts); |
| 42 | + await localStorage.SetItem<WeatherForecast[]>(key, forecasts); |
| 43 | + var fromSession = await sessionStorage.GetItem<WeatherForecast[]>(key); |
| 44 | + var fromLocal = await localStorage.GetItem<WeatherForecast[]>(key); |
| 45 | + } |
| 46 | +} |
| 47 | +``` |
| 48 | + |
| 49 | +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. |
| 50 | + |
| 51 | +```c# |
| 52 | +[Inject] |
| 53 | +protected SessionStorage sessionStorage; |
| 54 | + |
| 55 | +[Inject] |
| 56 | +protected LocalStorage localStorage; |
| 57 | + |
| 58 | +public Task LogSomething() |
| 59 | +{ |
| 60 | + var key = "forecasts"; |
| 61 | + await sessionStorage.SetItem<WeatherForecast[]>(key, forecasts); |
| 62 | + await localStorage.SetItem<WeatherForecast[]>(key, forecasts); |
| 63 | + var fromSession = await sessionStorage.GetItem<WeatherForecast[]>(key); |
| 64 | + var fromLocal = await localStorage.GetItem<WeatherForecast[]>(key); |
| 65 | +} |
| 66 | +``` |
| 67 | + |
| 68 | +# Contributions and feedback |
| 69 | + |
| 70 | +Please feel free to use the component, open issues, fix bugs or provide feedback. |
| 71 | + |
| 72 | +# Contributors |
| 73 | + |
| 74 | +The following people are the maintainers of the Blazor Extensions projects: |
| 75 | + |
| 76 | +- [Attila Hajdrik](https://github.com/attilah) |
| 77 | +- [Gutemberg Ribiero](https://github.com/galvesribeiro) |
0 commit comments