Blazor-State is a client side pipeline architecture utilizing MediatR with plugin behaviors.
If you are familiar with MediatR, Redux, or the Command Pattern you will feel right at home. All of the behaviors are written as plug-ins/middle-ware and attached to the MediatR pipeline. You can pick and choose which behaviors you would like to use or even write your own.
Please see our GitHub Site for source and filing of issues.
Blazor-State is available as a Nuget Package
dotnet add package Blazor-State
Or create new application based on the timewarp-blazor template
Blazor-State Implements a single
Store with a collection of
The MediatR pipeline allows for easy integration
by registering an interface with the DI container.
services.AddScoped(typeof(IPipelineBehavior<,>), typeof(CloneStateBehavior<,>)); services.AddScoped(typeof(IPipelineBehavior<,>), typeof(DevToolsBehavior<,>));
The three interfaces available to extend the Pipeline are
All of the behaviors in Blazor-State are implemented via one of these interfaces. You can integrate into the pipeline as well by implementing and registering one of these interfaces.
"Don't mutate state" always return a new state.
CloneStateBehavior behavior handles that for you by creating a clone of the
prior to processing the
State upon completion. (Single responsibility principle)
One of the nice features of redux is the developer tools. They allow for the monitoring of State transitions, time travel and more. This behavior implements the integration of these developer tools.
Redux Devtools implemented feautres:
Actions are logged to the Redux developer tools.
Time Travel is supported.
Other developer tools commands are not yet implemented (Would be good spot for a PR)
The pattern used by Blazor-State and MediatR has been around for many years and goes by different names. Given we are using MediatR will use the names associated with it but list other terminology here for clarification.
In Redux they call them "Action".
In UML they are "Signal".
In Command Pattern they are "Command"
In MediatR they are
This is the code that processes the
Request and returns the
In Redux they call them "Reducer".
(State in, State out, doesn't reduce anything yet they still call them that)
In Command Pattern we call them "Executor".
In MediatR they are
A Feature is the collection of the code needed to implement a particular Vertical Slice of the application.
On the server side we use the same architecture,
(see sample in Hosted Server), where the Features contain
Each endpoint has its own controller
which maps the HTTP Request to the
Request Object and then sends
it to the mediator.
Handler acts on the
Request and returns a
Server side follows the
Response out pattern.
A Feature Folder on the client side will contain a
Request and the
and any corresponding files needed for this feature.
The "Response" of client side feature is its
Client side follows the
State in new
State out pattern.
PureFunctions vs NonPureFunctions:
Blazor-State does not distinguish these. As they are processed via the pipeline the same. Thus, async calls to fetch data, send emails, or just update local state are implemented in the same manner. Although the developer should be aware that Handlers have side effects and if the developer chose they could mark the Requests as such. i.e. IRequestWithSideEffect
Jimmy Bogard (MediatR). Jimmy is an amazing developer and a knowledge sharer.
Through his course at https://11xengineering.com/ , his many blog posts on Los Techies and now https://jimmybogard.com/. I have learned great amounts.
Peter Morris (Blazor-Fluxor). Pete and I
have been friends for many years and he is an amazing developer and person who has taught me much.
Not surprisingly Pete and I think much alike.
We independently started working on our blazor state management
components. Although I started first :P (By like a few days)
Pete's component attempts to solve most of the same problems.
Blazor-State draws on the strengths of a proven pipeline in MediatR where as Fluxor
implements its own middle-ware.
If Blazor-State does not meet your needs be sure to checkout Fluxor.
Tor Hovland (Blazor-Redux). I have only know Tor for a short time via the gitter on Blazor but he is already stimulating ideas. If you use F# and need redux like functionality checkout his library.
Time is of the essence. Before developing a Pull Request I recommend opening an issue for discussion.
Please feel free to make suggestions and help out with the DocFx documentation. Refer to Markdown for how to write markdown files.