Introduction
Installation
Basic concepts
Getting Started
Entities
Actions
Events
Workflow
Error handling
Advanced usage
Examples
In addition to the basic workflow management features, XWorkflows offers several advanced functionalities to cater to complex workflow scenarios and customization requirements.
XWorkflows allows you to customize the execution of actions and events. By overriding methods in the action and event classes, you can implement specific behavior before and after the execution of actions and events. This enables you to integrate with external systems, perform additional validation, or modify the action/event data as needed.
public class CustomSubmitOrderAction : SubmitOrderAction
{
protected CustomSubmitOrderAction(SubmittedState state, SubmitOrderEvent e) : base(state, e)
{
}
// Override the Execute method to add custom logic before and after action execution
public override async Task<(WorkflowActionResult<bool>, SubmitOrderActionRequest)> Execute(OrderEntity data, SubmitOrderActionRequest p, CancellationToken cancellationToken)
{
// Custom pre-execution logic
Log("Executing CustomSubmitOrderAction...");
// Execute the base action's logic
var result = await base.Execute(data, p, cancellationToken);
// Custom post-execution logic
Log("CustomSubmitOrderAction executed successfully!");
return result;
}
}
XWorkflows allows you to pass custom parameters to actions and retrieve responses from actions. This allows you to provide additional data to actions and receive feedback after execution.
// Define custom action parameters and response
public class CustomActionParameters
{
// Define custom properties here
}
public class CustomActionResponse
{
// Define custom properties here
}
public class CustomAction : MyWorkflowAction<MyWorkflowEvent, MyWorkflowState, CustomActionParameters, CustomActionParameters, CustomActionResponse>
{
protected CustomAction(MyWorkflowState state, MyWorkflowEvent e) : base(state, e)
{
}
public override Task<(WorkflowActionResult<CustomActionResponse>, CustomActionParameters)> Execute(MyWorkflowEntity data, CustomActionParameters p, CancellationToken cancellationToken)
{
// Implement the action logic here
// Access custom action parameters
var customData = p;
// Return custom action response
var response = new CustomActionResponse { /* Populate properties */ };
return Task.FromResult((WorkflowActionResult<CustomActionResponse>.Succeeded(response), p));
}
}
XWorkflows allows you to manage multiple workflows for different entities in your application. Simply create separate custom workflow classes for each entity and register their relevant actions and states. This enables you to keep the workflows separate and organized, ensuring a clear and modular workflow management structure.
XWorkflows use dependency injection to register workflow related classes. In your Program.cs your should invoke method RegisterWorkflows.
XWorkflows provides flexibility in defining conditional transitions between states. You can override the AllowedTransitions method in a state class to define complex logic for allowing or denying state transitions based on specific conditions.
public class ConditionalTransitionState : MyWorkflowState
{
public override IEnumerable<Type> AllowedTransitions()
{
// Implement custom logic for conditional transitions
if (/* Some condition here */)
{
yield return typeof(AllowedAction);
}
else
{
yield return typeof(DeniedAction);
}
}
}