Integrate workflow client module¶
A client module
is provided to integrate workflow features within your bounded
context.
The rest of this document is devoted to explain how to integrate the workflow client module within your bounded context.
Add reference to the workflows client module¶
The first thing to do is to add a reference to the workflows client module project, as shown below:
XML | |
---|---|
Configure workflows client module¶
In your application module you have to depend on client module, and provide all
the information required by mean of WorkflowsClientModuleOptions
, including:
- which
DbContext
to use, throughSetDbContext
method - all available actions, specified through
AddWorkflowAction<YOUR_ACTION_DESCRIPTOR_TYPE>
method - finally, define the workflow for a given entity, through
AddWorkflow<TEntity>
We encourage you to use an extension method on WorkflowsClientModuleOptions
to
move workflow configuration away from the application composition method, for
the sake of readability.
Please consider moving the workflowId
to a public constant, this way it can be
referenced from deployment modules.
Configure the workflow¶
The workflow must be defined through the workflow builder, by invoking
AddWorkflow<TEntity>
method, where TEntity
is the entity for which we are
defining the workflow.
To know more about configuring the workflow, see here.
Seed definition using deployment tasks¶
Every entity supporting workflow must be given at least one template. It's important to include the template creation when defining deployment tasks.
Starting the workflow¶
The workflow must be started, you need to invoke StartWorkflow
method to have
it started and bound to the lifecycle defined by the workflow template for the
entity type.
If you are using consumers, you must inject IWorkflowEngine<TEntity>
and
call its StartWorkflow
method, typically when creating the entity. In the
other hand, if you are using sagas, you must invoke StartWorkflow
saga's
extension method, typically at InitialState
.
Once the workflow's been started, the rest of the workflow= lifecycle will be
driven by WorkflowTransitionConsumer
, until reaching a final state.