In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-02 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/01 Report--
Today, I would like to talk to you about how to understand the state machine library Stateless 3.0 on the .NET Core. Many people may not understand it very well. In order to make you understand better, the editor has summarized the following contents. I hope you can get something from this article.
Stateless is a simple library for creating state machines based on caching, and the latest version supports .NET Core 1.0. It is implemented not through the .NET Core, but by writing to the .NET Standard. Just as the API level abstracts out many underlying versions of Android,.NET Standard on the Android platform, it is a set of API that must be implemented on all .NET platforms.
To the developer's delight, Stateless 3.0 is a widely used and most compatible standard version based on .NET Standard 1.0. it can run almost anywhere, from the .NET Framework on the Windows platform, the .NET Core to Mac, and the Windows App Store, as well as all mobile platforms.
Characteristics:
Support most standard state organizations to build:
Support for any .NET type (numbers, strings, enumerations, etc.) states and triggers
Stratified state
State entry / exit event
Guard clause to support conditional conversion
Introspection.
At the same time, some useful extensions are provided:
Support for external state storage (for example, tracked properties by ORM)
Parameterized trigger
Reentrant state
DOT format chart export is supported.
Create a simple state machine using Stateless
Let's take a look at some code examples. Start by describing some finite states, such as an enumeration type and some finite "triggers" for changing states, just like developers, to start and close states and to switch triggers.
Another more practical example is Bug Tracker, where the source code is on GitHub. Here is a Bug and trigger state that causes a state change:
Enum State {Open, Assigned, Deferred, Resolved, Closed} enum Trigger {Assign, Defer, Resolve, Close}
Let's initialize the state, define the StateMachine, and pass parameters when the state is triggered if you like. For example, if you use Assign to trigger Bug, you can pass in "Scott" so that the Bug goes into the Assigned state-assigned to Scott.
State _ state = State.Open;StateMachine _ machine;StateMachine.TriggerWithParameters _ assignTrigger;string _ title;string _ assignee
In this example, the Bug constructor uses a state machine with a smooth interface that reads pretty well.
Public Bug (string title) {_ title = title; _ machine = new StateMachine (() = > _ state, s = > _ state = s); _ assignTrigger = _ machine.SetTriggerParameters (Trigger.Assign); _ machine.Configure (State.Open) .permit (Trigger.Assign, State.Assigned)
_ machine.Configure (State.Assigned) .SubstateOf (State.Open) .OnEntryFrom (_ assignTrigger, assignee = > OnAssigned (assignee)) .PermitReentry (Trigger.Assign) .permit (Trigger.Close, State.Closed) .permit (Trigger.Defer, State.Deferred) .OnExit (() = > OnDeassigned ()
_ machine.Configure (State.Deferred) .OnEntry (() = > _ assignee = null) .permit (Trigger.Assign, State.Assigned);}
For example, when the state is on, you can assign it, but because it is written (you can change it), you cannot close a Bug that is open and unallocated.
When Bug is assigned, you can close, delay, or reassign. This is PermitReentry (). Also, notice that Assigned is a sub-state.
You can change the trigger events in a stateful manner, and these events can be acted on according to your personal settings.
Void OnAssigned (string assignee) {if (_ assignee! = null & & assignee! = _ assignee) SendEmailToAssignee ("Don't forget to help the new employee."); _ assignee = assignee; SendEmailToAssignee ("You own it.");} void OnDeassigned () {SendEmailToAssignee ("You're off the hook.");} void SendEmailToAssignee (string message) {Console.WriteLine ("{0}, RE {1}: {2}", _ assignee, _ title, message);}
Having a good state machine library, such as Stateless, allows you to simulate state quickly. Can you share what the state machine you use in the project looks like?
After reading the above, do you have any further understanding of the state machine library Stateless 3.0 on the .NET Core? If you want to know more knowledge or related content, please follow the industry information channel, thank you for your support.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.