{"id":23740214,"url":"https://github.com/mustaddon/statemachine","last_synced_at":"2025-09-04T15:32:06.724Z","repository":{"id":65358905,"uuid":"181023909","full_name":"mustaddon/StateMachine","owner":"mustaddon","description":".NET Finite-state machine (FSM) with a fluent interface and mediators compatibility","archived":false,"fork":false,"pushed_at":"2024-11-16T11:44:45.000Z","size":520,"stargazers_count":4,"open_issues_count":0,"forks_count":3,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-12-16T18:11:38.483Z","etag":null,"topics":["csharp","dotnet","finite-state-machine","fluent-fsm","fluent-interface","fluent-workflow","fsm","mediator","mediatr","mediatr-extension","state","state-machine","state-management"],"latest_commit_sha":null,"homepage":"","language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/mustaddon.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2019-04-12T14:26:26.000Z","updated_at":"2024-11-16T11:44:49.000Z","dependencies_parsed_at":"2024-10-18T06:48:32.347Z","dependency_job_id":null,"html_url":"https://github.com/mustaddon/StateMachine","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mustaddon%2FStateMachine","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mustaddon%2FStateMachine/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mustaddon%2FStateMachine/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mustaddon%2FStateMachine/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mustaddon","download_url":"https://codeload.github.com/mustaddon/StateMachine/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":231970943,"owners_count":18453930,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["csharp","dotnet","finite-state-machine","fluent-fsm","fluent-interface","fluent-workflow","fsm","mediator","mediatr","mediatr-extension","state","state-machine","state-management"],"created_at":"2024-12-31T09:47:29.583Z","updated_at":"2024-12-31T09:47:30.202Z","avatar_url":"https://github.com/mustaddon.png","language":"C#","readme":"# FluentStateMachine [![NuGet version](https://badge.fury.io/nu/FluentStateMachine.svg)](http://badge.fury.io/nu/FluentStateMachine)\nFinite-state machine (FSM) with a fluent interface and mediators compatibility.\n\n## Example\n```C#\nenum States { S1, S2, S3 }\nenum Events { E1, E2, E3 }\n```\n```C#\nvar fsm = new FsmBuilder\u003cStates, Events\u003e(States.S1)\n    .OnEnter(x =\u003e Console.WriteLine($\"State change to {x.State} from {x.PrevState}\"))\n    .State(States.S1)\n        .On(Events.E1).Execute(x =\u003e { /* some operations */ return \"some results\"; })\n        .On(Events.E2).JumpTo(States.S2)\n    .State(States.S2)\n        .On(Events.E3).Enable(x =\u003e /* some conditions */ true).JumpTo(States.S3)\n    .State(States.S3)\n        .OnEnter(x =\u003e Console.WriteLine($\"Enter to final state\"))\n    .Build();\n\n\nConsole.WriteLine(fsm.Trigger(Events.E1));\nfsm.Trigger(Event.E2);\nfsm.Trigger(Event.E3);\n\n\n// Console output:\n// some results\n// State change to S2 from S1\n// State change to S3 from S2\n// Enter to final state\n```\n\n[ReadmeExample1.cs](https://github.com/mustaddon/StateMachine/blob/master/Examples/Example.ConsoleApp/ReadmeExample1.cs)\n\n\n## Example with type-based events\n```C#\nclass Event1 : IFsmEvent\u003cstring\u003e\n{\n    public int SomeProp { get; set; }\n}\n\nclass Event2 : IFsmEvent;\nclass Event3 : IFsmEvent;\n```\n```C#\nvar fsm = new FsmBuilder\u003cStates, Type\u003e(States.S1)\n    .OnEnter(x =\u003e Console.WriteLine($\"State change to {x.State} from {x.PrevState}\"))\n    .State(States.S1)\n        .On\u003cEvent1, string\u003e().Execute(x =\u003e $\"{x.Data.SomeProp} results\")\n        .On\u003cEvent2\u003e().JumpTo(States.S2)\n    .State(States.S2)\n        .On\u003cEvent3\u003e().JumpTo(States.S3)\n    .State(States.S3)\n        .OnEnter(x =\u003e Console.WriteLine($\"Enter to final state\"))\n    .Build();\n\n\nConsole.WriteLine(\n    fsm.Trigger(new Event1 { \n        SomeProp = 123 \n    }));\n\nfsm.Trigger(new Event2());\nfsm.Trigger(new Event3());\n\n\n// Console output:\n// 123 results\n// State change to S2 from S1\n// State change to S3 from S2\n// Enter to final state\n```\n[ReadmeExample2.cs](https://github.com/mustaddon/StateMachine/blob/master/Examples/Example.ConsoleApp/ReadmeExample2.cs)\n\n[Example of use for workflows](https://github.com/mustaddon/StateMachine/blob/master/Examples/Example.ConsoleApp/WorkflowExample.cs)\n\n[Using with MediatR](https://github.com/mustaddon/StateMachine/tree/master/FluentStateMachine.MediatR#fluentstatemachinemediatr-)\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmustaddon%2Fstatemachine","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmustaddon%2Fstatemachine","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmustaddon%2Fstatemachine/lists"}