appccelerate / statemachine

A .net library that lets you build state machines (hierarchical, async with fluent definition syntax and reporting capabilities).
Apache License 2.0
488 stars 128 forks source link

Feature/move all state to state container #54

Closed wtjerry closed 5 years ago

wtjerry commented 5 years ago

With this PR all state (as in "mutable state" and not "state machine states") is moved to StateContainer. This also includes pending events, which are now also saved / loaded.

API changes:

The interface IStateMachineSaver got a new method void SaveEvents(IReadOnlyCollection<EventInformation<TEvent>> events) for saving pending events. The complementing interface IStateMachineLoader got also a new method IReadOnlyCollection<EventInformation<TEvent>> LoadEvents().

Same goes for the Async versions of them. But there are 2 new methods each. One for normal events and one for priority events.

Internal changes:

IExtensionInternal

There is a new interface IExtensionInternal interface that code will use. it is equivalent to the API interface IExtension apart from not requiring the IStateMachineInfo parameter. That parameter is already passed via constructor.

Reason: the IStateMachineInfo parameter had to be passed around much of the codebase just to pass it to the IExtension methods.

Pending Events

Pending events were moved from the StateContainer to have all state at the same place.

TState in StateContainer

Changed StateContainer.CurrentState to TState from IStateDefinition and removed StateContainer.CurrentStateId. Also change ILastActiveStateModifier to deal with TState.

Reason: All savable "things" now use TState so when loading a StateMachine there are no issues with references to other IStateDefinitions