JasonState.Extension
0.0.1
dotnet add package JasonState.Extension --version 0.0.1
NuGet\Install-Package JasonState.Extension -Version 0.0.1
<PackageReference Include="JasonState.Extension" Version="0.0.1" />
paket add JasonState.Extension --version 0.0.1
#r "nuget: JasonState.Extension, 0.0.1"
// Install JasonState.Extension as a Cake Addin #addin nuget:?package=JasonState.Extension&version=0.0.1 // Install JasonState.Extension as a Cake Tool #tool nuget:?package=JasonState.Extension&version=0.0.1
Jason State
Jason State is a simple state machine implementation. It's configured by a JSON file.
Supported Platforms
Features
- Dependency injection friendly (can also be used standalone, see below)
Table of Contents
Why Jason State?
- No need to worry about implementing State Pattern. With Jason State, it is already implemented!
- Because you use state pattern, your code is cleaner.
- Let the business need change! It'll give you the flexibility to change the flow just by the JSON file you provide. No need for deployment!
- Supports sync and async operations!
Installation
Usage
Json
First you need to provide a valid JSON file. This JSON file must contain a States array. This array should have objects.
- Namespace: namespace of your state
- Name: Just the name of your state file
- NextState: array contains objects
- Condition: The condition for the states execution.
- State: State is next state's name. No need to provide namespace
- ErrorState: Name of your state's error state. This state will be executed only if the current state has an exception that you don't handle. Error state can be different for each state.
An example of a valid JSON file can be found throug
{
"States": [
{
"Namespace": "TestClient.Impls.States",
"Name": "InitialState",
"NextState": [
{
"Condition": "!string.IsNullOrEmpty(FromEmail) && FromEmail.Equals(\"aksel@test.com\")",
"State": "ValidatePaymentState"
},
{
"Condition": "!string.IsNullOrEmpty(FromEmail) && FromEmail.Equals(\"test@test.com\")",
"State": "FinalState"
}
],
"ErrorState": "ErrorState"
},
{
"Namespace": "TestClient.Impls.States",
"Name": "ErrorState",
"NextState": [
{
"Condition": "true",
"State": "FinalState"
}
],
"ErrorState": null
},
{
"Namespace": "TestClient.Impls.States",
"Name": "FinalState",
"NextState": null,
"ErrorState": null
}
]
}
State Implementation
States must inherit from and implement Execute, or ExecuteAsync, method with your state context. You can use any dependency injection framework for construction injections. It will not break anything.
public class InitialState : BaseState<TestStateContext>
{
public override void Execute(TestStateContext context)
{
// do the magic
}
}
State Context
Jason State allows you to add any kind of object to the context. Everything you need during the state execution should be in the context.
public class TestStateContext
{
public long CreditCardNumber { get; set; }
public string CardHolderName { get; set; }
public decimal Amount { get; set; }
}
public class InitialState : BaseState<TestStateContext>
{
public override void Execute(TestStateContext context)
{
context.CreditCardNumber = "4545454545454545";
}
}
Microsoft.Extensions.DependencyInjection Initialization
By referencing JasonState.Extension, register necessary dependencies to ServiceCollection as follows
serviceCollection.AddJasonState<TestStateContext>();
or
serviceCollection.AddAsyncJasonState<TestStateContext>();
Samples
TestClient can be found <br /> AsyncTestClient can be found
License
Licensed under MIT, see LICENSE for the full text.
Product | Versions 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 | 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 is compatible. |
.NET Framework | net461 was computed. net462 was computed. 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. |
-
.NETStandard 2.0
- JasonState (>= 0.0.1)
- Microsoft.Extensions.DependencyInjection (>= 2.2.0)
-
.NETStandard 2.1
- JasonState (>= 0.0.1)
- Microsoft.Extensions.DependencyInjection (>= 2.2.0)
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 |
---|---|---|
0.0.1 | 546 | 10/13/2019 |