Arora.Blazor.StateContainer
1.0.1
See the version list below for details.
dotnet add package Arora.Blazor.StateContainer --version 1.0.1
NuGet\Install-Package Arora.Blazor.StateContainer -Version 1.0.1
<PackageReference Include="Arora.Blazor.StateContainer" Version="1.0.1" />
paket add Arora.Blazor.StateContainer --version 1.0.1
#r "nuget: Arora.Blazor.StateContainer, 1.0.1"
// Install Arora.Blazor.StateContainer as a Cake Addin #addin nuget:?package=Arora.Blazor.StateContainer&version=1.0.1 // Install Arora.Blazor.StateContainer as a Cake Tool #tool nuget:?package=Arora.Blazor.StateContainer&version=1.0.1
Arora.Blazor.StateContainer
Arora.Blazor.StateContainer is a .NET library that provides a simple state container implementation for Blazor applications. The library defines a StateContainer
class that can be used to store and manage application state, and an extension method AddStateContainer()
that can be used to register the StateContainer with the dependency injection container.
Installation
You can install the Arora.Blazor.StateContainer library using the .NET CLI:
dotnet add package Arora.Blazor.StateContainer
Usage
Top-level statements
If you're using C# 9 or later with top-level statements, you can use the Arora.Blazor.StateContainer library as follows:
using Arora.Blazor.StateContainer;
var builder = WebApplication.CreateBuilder(args);
builder.Services.AddStateContainer();
var app = builder.Build();
app.Run();
Old-style program and Startup
If you're using an older version of C# or the Program.cs and Startup.cs files in your project, you can use the Arora.Blazor.StateContainer library as follows:
using Arora.Blazor.StateContainer;
public class Startup
{
public void ConfigureServices(IServiceCollection services)
{
services.AddStateContainer();
}
}
public class Program
{
public static void Main(string[] args)
{
CreateHostBuilder(args).Build().Run();
}
public static IHostBuilder CreateHostBuilder(string[] args) =>
Host.CreateDefaultBuilder(args)
.ConfigureWebHostDefaults(webBuilder =>
{
webBuilder.UseStartup<Startup>();
});
}
Steps
- Add the following using statement:
using Arora.Blazor.StateContainer;
@using Arora.Blazor.StateContainer;
- In your Blazor component, use the
@inject
directive to inject theStateContainer
instance:
@inject StateContainer State
- Use the StateContainer instance in your component to update the state:
<p>Count: @count</p>
<button @onclick="IncrementCount">Increment</button>
@code {
private int count = 0;
private void IncrementCount()
{
count++;
State.NotifyStateChanged();
}
protected override void OnInitialized()
{
State.OnChange += StateHasChanged;
}
public void Dispose()
{
State.OnChange -= StateHasChanged;
}
}
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 was computed. net5.0-windows was computed. net6.0 is compatible. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. 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. |
.NET Core | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
.NET Standard | netstandard2.0 is compatible. netstandard2.1 was computed. |
.NET Framework | net461 was computed. net462 is compatible. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
MonoAndroid | monoandroid was computed. |
MonoMac | monomac was computed. |
MonoTouch | monotouch was computed. |
Tizen | tizen40 was computed. tizen60 was computed. |
Xamarin.iOS | xamarinios was computed. |
Xamarin.Mac | xamarinmac was computed. |
Xamarin.TVOS | xamarintvos was computed. |
Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETFramework 4.6.2
- Microsoft.Extensions.DependencyInjection (>= 7.0.0)
-
.NETStandard 2.0
- Microsoft.Extensions.DependencyInjection (>= 7.0.0)
-
net6.0
- Microsoft.Extensions.DependencyInjection (>= 7.0.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.