![]() |
VOOZH | about |
dotnet add package Bloc.NET --version 2.0.0
NuGet\Install-Package Bloc.NET -Version 2.0.0
<PackageReference Include="Bloc.NET" Version="2.0.0" />
<PackageVersion Include="Bloc.NET" Version="2.0.0" />Directory.Packages.props
<PackageReference Include="Bloc.NET" />Project file
paket add Bloc.NET --version 2.0.0
#r "nuget: Bloc.NET, 2.0.0"
#:package Bloc.NET@2.0.0
#addin nuget:?package=Bloc.NET&version=2.0.0Install as a Cake Addin
#tool nuget:?package=Bloc.NET&version=2.0.0Install as a Cake Tool
👁 Chickensoft Badge
👁 Discord
👁 Read the docs
A predictable state management library for C# that helps implement the BLoC design pattern.
<p align="center"> <img alt="Bloc.NET" src="Bloc.NET/icon.png" width="200"> </p>
You may know this library from it's more famous counterpart in the Dart/Flutter universe — but there's no reason we can't have one for .NET, too! Thanks to Felix (the creator of the original Bloc library) for consulting on this C# port.
In some ways, a bloc is similar to a state machine, but does not require the developer to define the entire table of state transitions ahead of time. Instead of being told to transition to a specific state, blocs listen to a stream of events and yield out states.
The increase in flexibility that comes from using blocs reduces the pain of implementing complex or nested/hierarchical state machines (and state charts, for that matter). The reduction of code allows the developer to focus more clearly on constructing the correct state in response to events, but does lack the rigidity of a state machine. Feel free to use whatever patterns are appropriate for your application.
There are a few things to be aware of regarding this implementations:
No docs! If you're interested in the pattern, I suggest reading the documentation for the Dart/Flutter version of Bloc. Dart and C# are both object-oriented, managed languages with garbage collection, so the concepts are similar enough.
Not actually equivalent to modern Dart/Flutter blocs. The bloc implementation in this library cannot support concurrent events — all events are processed sequentially and in-order. If events take a while to process, they simply queue up. This is equivalent to how the original Bloc library worked prior to Bloc v8.
Both asynchronous and synchronous implementations are provided for C#. The Dart/Flutter implementation does not have a specific synchronous implementation. Since C# is commonly used in game development (and I ported this package to use it with game development), I am providing a synchronous implementation as I believe it will be useful in many situations.
The synchronous implementation differs slightly from the asynchronous one: if an error occurs in the asynchronous implementation, it does not throw and stop execution (since the event is processed asynchronously, errors are not thrown as they would not even be in the same context of the event that triggered the error). Instead, the error is added to the bloc and the bloc can choose how to handle it.
The synchronous implementation, however, will throw an exception when an event is added that triggers an invalid state. I believe this is desirable as it greatly facilitates debugging in simpler situations where forcing everything to be asynchronous is overly complex or too much of a performance hit.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net5.0 net5.0 was computed. net5.0-windows net5.0-windows was computed. net6.0 net6.0 was computed. net6.0-android net6.0-android was computed. net6.0-ios net6.0-ios was computed. net6.0-maccatalyst net6.0-maccatalyst was computed. net6.0-macos net6.0-macos was computed. net6.0-tvos net6.0-tvos was computed. net6.0-windows net6.0-windows was computed. net7.0 net7.0 was computed. net7.0-android net7.0-android was computed. net7.0-ios net7.0-ios was computed. net7.0-maccatalyst net7.0-maccatalyst was computed. net7.0-macos net7.0-macos was computed. net7.0-tvos net7.0-tvos was computed. net7.0-windows net7.0-windows was computed. net8.0 net8.0 was computed. net8.0-android net8.0-android was computed. net8.0-browser net8.0-browser was computed. net8.0-ios net8.0-ios was computed. net8.0-maccatalyst net8.0-maccatalyst was computed. net8.0-macos net8.0-macos was computed. net8.0-tvos net8.0-tvos was computed. net8.0-windows net8.0-windows was computed. net9.0 net9.0 was computed. net9.0-android net9.0-android was computed. net9.0-browser net9.0-browser was computed. net9.0-ios net9.0-ios was computed. net9.0-maccatalyst net9.0-maccatalyst was computed. net9.0-macos net9.0-macos was computed. net9.0-tvos net9.0-tvos was computed. net9.0-windows net9.0-windows was computed. net10.0 net10.0 was computed. net10.0-android net10.0-android was computed. net10.0-browser net10.0-browser was computed. net10.0-ios net10.0-ios was computed. net10.0-maccatalyst net10.0-maccatalyst was computed. net10.0-macos net10.0-macos was computed. net10.0-tvos net10.0-tvos was computed. net10.0-windows net10.0-windows was computed. |
| .NET Core | netcoreapp3.0 netcoreapp3.0 was computed. netcoreapp3.1 netcoreapp3.1 was computed. |
| .NET Standard | netstandard2.1 netstandard2.1 is compatible. |
| MonoAndroid | monoandroid monoandroid was computed. |
| MonoMac | monomac monomac was computed. |
| MonoTouch | monotouch monotouch was computed. |
| Tizen | tizen60 tizen60 was computed. |
| Xamarin.iOS | xamarinios xamarinios was computed. |
| Xamarin.Mac | xamarinmac xamarinmac was computed. |
| Xamarin.TVOS | xamarintvos xamarintvos was computed. |
| Xamarin.WatchOS | xamarinwatchos xamarinwatchos was computed. |
This package is not used by any NuGet packages.
This package is not used by any popular GitHub repositories.
Bloc.NET release.