Scenarios
A scenario is a combination of actions being performed following a script. In the Chaplin framework we call these actions compositions. A scenario can be played by calling its endpoint or programmatically by a play method on the playing actor.
FuncScenario
A FuncScenario is a scenario which is programmed in a static function instead of a class. A FuncScenario is quicker to setup but provides less configuration options.
Events
A scenario can trigger events by using the Fire()
method. Events can be fired asynchronous as well with the FireAsync()
method. When a scenario is watched by a watcher, the watcher can act on the events which are fired. All scenarios trigger 4 events by default: Playing, Ending, Before and After.
Composition
The composition pattern has been introduced as an alternative for the provider pattern. The composition pattern can be used for the same use cases. Chaplin uses composition because the pattern fits better with the movie pattern in which the director is responsible for the composition of a scenario.
Examples
The scenario Calculate
with the role Formula
needs to calculate a number based on 2 numbers. Customer A wants the sum of those numbers and Customer B wants you to multiply them. With the composition pattern you are able to use the same scenario for both customers and you will only need to change the Director in each customer's individual server project.
Step 1: Build the scenario
If you want the director to compose certain parts of a scenario, we have to start by making the scenario itself.
Step 2: Create the compositions
In this step we make the operations for each client. In this example they are static methods in the same class but this isn't necessary at all. You could create new projects for each customer and place the composition in there.
Step 3: Configure the Director
In the Director we register a new Composer in the CollectComposers
method. In the Composer you can access a scenario's properties. In this case we set the Operate
property to the desired operation for each customer.
CollectComposers
method Customer A:
CollectComposers
method Customer B: