read more about XWorkflows documentation here
XWorkflows is a .NET library designed to simplify the management of workflows on entities, providing a clean and organized way to handle state transitions and actions for your entities. With XWorkflows, you can easily define and enforce a set of state transitions and actions, reducing spaghetti code and duplication in your application.
Before diving into the details of the library, it's essential to understand some of the key concepts and terms used within XWorkflows:
dotnet add package XWorkflows
Here's a basic example to create a workflow for an order entity with three actions: Create, Submit, and Cancel:
// Define your entity class
public class OrderEntity : IWorkflowStateEntity<State>
{
// Implement IWorkflowStateEntity members...
}
// Create your custom states
public class CreateOrderState : MyWorkflowState
{
// Implement CreateOrderState specific logic...
}
public class SubmitOrderState : MyWorkflowState
{
// Implement SubmitOrderState specific logic...
}
public class CancelOrderState : MyWorkflowState
{
// Implement CancelOrderState specific logic...
}
// Define your actions
public class CreateOrderAction : MyWorkflowAction<CreateOrderEvent, CreateOrderState, CreateOrderActionRequest, CreateOrderActionRequest, string>, IWorkflowStartAction
{
// Implement CreateOrderAction logic...
}
public class SubmitOrderAction : MyWorkflowAction<SubmitOrderEvent, SubmitOrderState, SubmitOrderActionRequest, SubmitOrderActionRequest, bool>
{
// Implement SubmitOrderAction logic...
}
public class CancelOrderAction : MyWorkflowAction<CancelOrderEvent, CancelOrderState, CancelOrderActionRequest, CancelOrderActionRequest, bool>
{
// Implement CancelOrderAction logic...
}
// Define your workflow
public class OrderWorkflow : WorkflowBase<OrderWorkflow, OrderEntity, State>
{
public OrderWorkflow(IEnumerable<IWorkflowOwner<OrderWorkflow>> actions) : base(actions)
{
}
}
read more about XWorkflows documentation here
GitHub Examples repository: https://github.com/dejandjenic/XWorkflows.Examples