ZeroAlloc.Flux
2.0.1
dotnet add package ZeroAlloc.Flux --version 2.0.1
NuGet\Install-Package ZeroAlloc.Flux -Version 2.0.1
<PackageReference Include="ZeroAlloc.Flux" Version="2.0.1" />
<PackageVersion Include="ZeroAlloc.Flux" Version="2.0.1" />
<PackageReference Include="ZeroAlloc.Flux" />
paket add ZeroAlloc.Flux --version 2.0.1
#r "nuget: ZeroAlloc.Flux, 2.0.1"
#:package ZeroAlloc.Flux@2.0.1
#addin nuget:?package=ZeroAlloc.Flux&version=2.0.1
#tool nuget:?package=ZeroAlloc.Flux&version=2.0.1
ZeroAlloc.Flux
Source-generated Flux/Redux state management for .NET and Blazor, an alternative to Fluxor: no reflection, no allocations when you dispatch, NativeAOT-ready.
Why ZeroAlloc.Flux
- 0 B per dispatch. Dispatching an action, fanning it out to several features, notifying subscribers and reading the state allocate nothing; tests assert each path on net10.0 and net11.0, including dispatch to a store that a Blazor
FluxComponentsubscribes to. - Dispatch is generated code. The dispatcher is built at compile time from your
[Reducer]methods and resolves to a direct call per action type: no handler dictionary, no reflection. - Works under NativeAOT and trimming. CI publishes and runs a NativeAOT app, and builds a Blazor WebAssembly app, on every build.
- Compile-time diagnostics. A wrong reducer signature, a duplicate reducer or a feature that is not
partialstops the build with aZFLUXerror instead of failing at runtime.
Install
dotnet add package ZeroAlloc.Flux
The source generator ships inside the package. A console app also needs a DI container, for example dotnet add package Microsoft.Extensions.DependencyInjection; ASP.NET Core and Blazor already have one.
Quick start
using Microsoft.Extensions.DependencyInjection;
using ZeroAlloc.Flux;
using ZeroAlloc.Flux.Generated;
using var sp = new ServiceCollection().AddZeroAllocFlux().BuildServiceProvider();
var dispatcher = sp.GetRequiredService<IDispatcher>();
var counter = sp.GetRequiredService<IStore<CounterState>>();
counter.StateChanged += state => Console.WriteLine($"Count is now {state.Count}");
await dispatcher.DispatchAsync(new Increment(5)); // Count is now 5
await dispatcher.DispatchAsync(new Increment(3)); // Count is now 8
[Feature]
public readonly partial record struct CounterState(int Count);
public readonly record struct Increment(int Amount);
public static class CounterReducers
{
[Reducer]
public static CounterState On(CounterState state, Increment action)
=> state with { Count = state.Count + action.Amount };
}
State is a record, actions are plain types with no marker interface, and reducers are static methods. The generator writes the store, the dispatcher and AddZeroAllocFlux.
What you get
- Stores per state slice, safe for concurrent dispatch and reads, with a
StateChangedevent. Core concepts - One action, many features: every reducer for an action runs, as in Redux and Fluxor.
- Custom initial state through a factory that can use your services. Initial state
- Effects as plain services that inject
IDispatcher, do async work and dispatch the result. Effects - Blazor support:
ZeroAlloc.Flux.BlazoraddsFluxComponent, which re-renders when a store it subscribes to changes. Blazor guide - Build-time checks, ZFLUX001 to ZFLUX009. Diagnostics
- Targets
net10.0andnet11.0.
Performance
Exact allocation budgets, each asserted by an AllocationGate test over 1,000 calls in CI:
| Hot path | Allocated |
|---|---|
DispatchAsync to one record struct feature |
0 B |
DispatchAsync fanned out to two features, each raising StateChanged to a subscriber |
0 B |
IStore<TState>.Value read |
0 B |
The budgets hold for the library's own work; a record class feature allocates the new state your reducer returns. What still allocates, why dispatch does not, and how to run the benchmarks: docs/performance.md.
Learn more
- Documentation site: flux.zeroalloc.net
- Documentation source: docs/, starting with getting started
- Runnable examples:
samples/has a console app, a Blazor WebAssembly counter and the NativeAOT smoke test - Related packages: the ZeroAlloc family, including ZeroAlloc.Mediator for request and notification dispatch
- Contributing: issues and pull requests are welcome on GitHub
- License: MIT
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net10.0 is compatible. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. net11.0 is compatible. |
-
net10.0
-
net11.0
- No dependencies.
NuGet packages (1)
Showing the top 1 NuGet packages that depend on ZeroAlloc.Flux:
| Package | Downloads |
|---|---|
|
ZeroAlloc.Flux.Blazor
Blazor host adapter for ZeroAlloc.Flux — FluxComponent base class and DI extensions. |
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 2.0.1 | 63 | 11/22/2026 |
| 2.0.0 | 103 | 11/22/2026 |
| 1.4.1 | 196 | 11/16/2026 |
| 1.4.0 | 515 | 11/11/2026 |
| 1.3.0 | 613 | 10/28/2026 |
| 1.2.2 | 213 | 10/16/2026 |
| 1.2.1 | 134 | 10/16/2026 |
| 1.2.0 | 129 | 10/15/2026 |
| 1.1.11 | 1,111 | 10/12/2026 |
| 1.1.10 | 134 | 10/12/2026 |
| 1.1.9 | 130 | 10/11/2026 |
| 1.1.8 | 134 | 9/30/2026 |
| 1.1.7 | 142 | 9/30/2026 |
| 1.1.6 | 117 | 9/30/2026 |
| 1.1.5 | 136 | 9/28/2026 |
| 1.1.4 | 175 | 9/20/2026 |
| 1.1.3 | 132 | 9/20/2026 |
| 1.1.2 | 135 | 9/20/2026 |
| 1.1.1 | 165 | 9/14/2026 |
| 1.1.0 | 310 | 8/7/2026 |