Getting started
The following guide helps you set up DCR.Workflow for integration in a larger project in the most common way.
This guide assumes that:
- you will be accessing DCR.Workflow using dependency injection,
- that you are using dotnet 6 or later,
- that you will be using the DCR Workflow middleware layer.
Setup
Here are the steps:
- Add the
DCR.Workflow
nuget package to your project. - Add Runtime as a service. E.g., in a razor application in
Program.cs
:
Warning
It looks like the sample you are looking for does not exist.
Initialization
When a case is created, it is often necessary to run initially pending robots before any user interaction takes place. To facilitate this, you can use the Initialize method provided by the Runtime class.
DCR.Workflow.Runtime middleware = ...
Model model = await ... // Load "model" from persistent storage.
var context = new Dictionary<string, string> { // Provide contextual information for
{ "CaseId": /* caseid */, // ativity exection
"UserId": /* id of current user */
}
};
await middleware.Initialize(model, context);
... // Persist to storage with a preferred method
Executing events
Use one of the Runtime.Execute methods to advance model state, executing effects in the process.
Applications commonly proceed as follows:
DCR.Workflow.Runtime middleware = ... // Acquire Runtime via DI
Model model = await ... // Load "model" from persistent storage.
var context = new Dictionary<string, string> { // Provide contextual information for
{ "CaseId": /* caseid */, // ativity exection
"UserId": /* id of current user */
}
};
await middleware.Execute(model, activity); // Update state of model by executing "activity".
// "Execute" runs side-effects and executes
// additional activities as required by "model".
await ... (model.ToXDocument()) // Write back "model" to persistent storage
Caution
The DCR.Workflow.Model.Execute(DCR.Workflow.Activity,DCR.Core.Data.value) method on the Model class does not execute effects. Use as described above if you execute effects.