Arora.Blazor.StateContainer 1.0.2

dotnet add package Arora.Blazor.StateContainer --version 1.0.2
NuGet\Install-Package Arora.Blazor.StateContainer -Version 1.0.2
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="Arora.Blazor.StateContainer" Version="1.0.2" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Arora.Blazor.StateContainer --version 1.0.2
#r "nuget: Arora.Blazor.StateContainer, 1.0.2"
#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 Arora.Blazor.StateContainer as a Cake Addin
#addin nuget:?package=Arora.Blazor.StateContainer&version=1.0.2

// Install Arora.Blazor.StateContainer as a Cake Tool
#tool nuget:?package=Arora.Blazor.StateContainer&version=1.0.2

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

  1. Add the following using statement:
using Arora.Blazor.StateContainer;
@using Arora.Blazor.StateContainer;
  1. In your Blazor component, use the @inject directive to inject the StateContainer instance:
@inject StateContainer State
  1. 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 Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  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 netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.1 is compatible. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.0.2 243 11/15/2023
1.0.1 284 2/12/2023