Shaunebu.Common.WorkflowManager
1.0.0
dotnet add package Shaunebu.Common.WorkflowManager --version 1.0.0
NuGet\Install-Package Shaunebu.Common.WorkflowManager -Version 1.0.0
<PackageReference Include="Shaunebu.Common.WorkflowManager" Version="1.0.0" />
<PackageVersion Include="Shaunebu.Common.WorkflowManager" Version="1.0.0" />
<PackageReference Include="Shaunebu.Common.WorkflowManager" />
paket add Shaunebu.Common.WorkflowManager --version 1.0.0
#r "nuget: Shaunebu.Common.WorkflowManager, 1.0.0"
#:package Shaunebu.Common.WorkflowManager@1.0.0
#addin nuget:?package=Shaunebu.Common.WorkflowManager&version=1.0.0
#tool nuget:?package=Shaunebu.Common.WorkflowManager&version=1.0.0
This is a .NET library for managing workflows and business processes in .NET MAUI or console applications. It provides a flexible engine to define, execute, monitor, and persist workflows.
๐ Features
| Library | ๐ฏ Focus | โก Complexity | ๐ ๏ธ Main Use Cases | โ Key Features |
|---|---|---|---|---|
| Shaunebu.Common.WorkflowManager | Business process automation | High | Order processing, multi-step approvals, complex workflows | Workflow definitions, decisions, parallel branches, persistence, events, analytics |
| DurableTask / Durable Functions | Orchestrating long-running tasks in Azure | High | Cloud workflows, long-running jobs | Durable orchestration, timers, retries, events, Azure integration |
| Elsa Workflows | Workflow engine for .NET | High | Approval flows, human workflows, automation | Visual workflow designer, activities library, persistence, REST triggers, events |
| Hangfire | Background job scheduling | Medium | Fire-and-forget, recurring jobs, batch tasks | Queued jobs, retries, delayed execution, dashboard, persistence |
| MassTransit (with Sagas) | Distributed workflows / messaging | High | Event-driven microservices workflows | State machine sagas, event-driven transitions, retries, message orchestration |
| Stateless | Lightweight state machines | Medium | UI wizards, finite state machines, simple process automation | Fluent API, states & triggers, hierarchical states, events |
Declarative Workflow Definitions: Define nodes, decisions, parallel branches, and transitions.
Activities System: Encapsulate business logic in reusable workflow activities.
Workflow Execution Engine: Start, resume, suspend, cancel workflows with real-time progress.
Persistence & State Management: Save workflow state to memory, SQLite, or custom storage.
Parallel & Conditional Flows: Support parallel branches, decision trees, and external event waits.
Monitoring & Analytics: Track workflow progress, errors, and execution history.
Integration with .NET MAUI: Display dynamic workflow dashboards and step views.
๐งฉ Advanced Workflow Features
Compensation & Error Handling: Define compensating activities to revert workflow steps when failures occur.
Timeouts & Wait Nodes: Pause execution until an external event occurs or a timeout expires.
Parallel Branching & Joining: Execute multiple activities concurrently and synchronize on join nodes.
Decision Trees: Support complex branching logic based on workflow context data.
๐ Workflow Lifecycle
Workflows have a well-defined lifecycle:
Created โ Workflow instance is initialized.
Running โ Node execution in progress.
Suspended โ Temporarily paused, can resume later.
Cancelled โ Workflow execution stopped by user or system.
Completed โ Successfully finished all nodes.
Failed โ Execution failed and optionally triggered compensation.
๐๏ธ Architecture Overview
+-----------------------+
| Workflow Definition |
| (Nodes + Transitions)|
+-----------+-----------+
|
v
+-----------------------+
| Workflow Engine |
| Executes workflow |
| Handles transitions |
+-----------+-----------+
|
v
+-----------------------+
| Workflow Persistence |
| Stores state & logs |
+-----------------------+
๐ Extensibility
Custom Activities โ Implement
WorkflowActivityfor domain-specific logic.Custom Persistence โ Implement
IWorkflowPersistencefor databases like SQLite, PostgreSQL, or cloud storage.Custom Serialization โ Override workflow serialization with JSON, XML, or protobuf.
๐ Monitoring & Analytics
Track active workflow instances.
Monitor progress per node and phase.
Retrieve execution history with timestamps and errors.
Identify bottlenecks in parallel or decision-heavy workflows.
๐๏ธ Integration Points
Dependency Injection: Register engine, activities, and persistence in .NET MAUI or ASP.NET Core.
UI Integration: Bind workflow instance data to dashboards, progress bars, and step views.
Event-Driven: Subscribe to workflow events (node started, completed, failed) for notifications or logging.
๐ก Best Practices
Keep activities small and focused.
Use decision nodes instead of deeply nested conditions.
Persist state frequently for resiliency in long-running workflows.
Reuse activities across workflows for maintainability.
๐งช Testing & Debugging
Unit Test Activities independently from the engine.
Simulate workflows with in-memory persistence for integration tests.
Use
DependencyGraphDot()to visualize workflow structure during debugging.
๐ฆ Installation
Install via NuGet:
dotnet add package Shaunebu.Common.WorkflowManager
๐๏ธ Core Concepts
Workflow Definition
A workflow consists of nodes and transitions:
Start Node: Entry point of the workflow.
Activity Node: Executes a business logic unit.
Decision Node: Conditional branching.
Parallel Node: Executes branches in parallel.
End Node: Marks workflow completion.
Example WorkflowNode:
public abstract class WorkflowNode
{
public string Id { get; set; }
public string Name { get; set; }
public NodeType Type { get; set; }
public abstract Task<NodeResult> ExecuteAsync(WorkflowContext context);
}
Workflow Context
Stores runtime data and workflow status:
public class WorkflowContext
{
public string InstanceId { get; }
public string CurrentNodeId { get; }
public WorkflowStatus Status { get; }
public void SetData<T>(string key, T value);
public T GetData<T>(string key);
}
Workflow Activity
Encapsulates business logic:
public class ValidateOrderActivity : WorkflowActivity
{
public override async Task<ActivityResult> ExecuteAsync(WorkflowContext context)
{
var order = context.GetData<Order>("Order");
// Validate order logic
return ActivityResult.Success();
}
}
โ๏ธ Engine API
public class WorkflowEngine
{
public WorkflowEngine(IWorkflowPersistence persistence, ILogger? logger = null);
public Task<WorkflowExecutionResult> StartAsync(WorkflowDefinition definition, object inputData, CancellationToken token);
public Task<WorkflowExecutionResult> ResumeAsync(string instanceId, CancellationToken token);
public Task<IEnumerable<WorkflowInstance>> GetActiveInstancesAsync();
public Task<WorkflowInstance> GetInstanceAsync(string instanceId);
public event EventHandler<WorkflowEvent> WorkflowEvent;
}
๐ก Usage Example
using Shaunebu.Common.WorkflowManager.Builder;
using Shaunebu.Common.WorkflowManager.Engine;
using Shaunebu.Common.WorkflowManager.Client.Activities;
using Shaunebu.Common.WorkflowManager.Persistence;
// Setup persistence and engine
var persistence = new InMemoryWorkflowPersistence();
var engine = new WorkflowEngine(persistence, logger: null);
// Build workflow definition
var workflow = new WorkflowDefinitionBuilder("OrderProcessing")
.WithVersion("1.0")
.AddStart("start")
.AddActivity("validateOrder", typeof(ValidateOrderActivity))
.AddDecision("paymentCheck")
.AddActivity("processPayment", typeof(ProcessPaymentActivity))
.AddActivity("generateInvoice", typeof(GenerateInvoiceActivity))
.AddActivity("notifyFailure", typeof(NotifyFailureActivity))
.AddEnd("end")
.AddTransition("start", "validateOrder")
.AddTransition("validateOrder", "paymentCheck")
.AddTransition("paymentCheck", "processPayment", async ctx => await Task.FromResult(ctx.Get<bool>("orderValid")))
.AddTransition("paymentCheck", "notifyFailure", async ctx => await Task.FromResult(!ctx.Get<bool>("orderValid")))
.AddTransition("processPayment", "generateInvoice")
.AddTransition("generateInvoice", "end")
.AddTransition("notifyFailure", "end")
.Build();
// Start workflow
var result = await engine.StartAsync(workflow, new { OrderId = 1234 }, CancellationToken.None);
Console.WriteLine($"Workflow success: {result.IsSuccess}");
๐ Visualization
Generate DOT graph for your workflow:
public string DependencyGraphDot(WorkflowDefinition def)
{
var sb = new StringBuilder();
sb.AppendLine("digraph Workflow {");
foreach (var kvp in def.Nodes)
{
var nodeId = kvp.Key;
var transitions = def.Transitions.Where(tr => tr.FromNodeId == nodeId);
foreach (var tr in transitions)
{
sb.AppendLine($"\"{tr.FromNodeId}\" -> \"{tr.ToNodeId}\";");
}
}
sb.AppendLine("}");
return sb.ToString();
}
๐ ๏ธ Persistence
Interface to implement custom persistence:
public interface IWorkflowPersistence
{
Task SaveInstanceAsync(WorkflowInstance instance);
Task<WorkflowInstance> LoadInstanceAsync(string instanceId);
Task DeleteInstanceAsync(string instanceId);
Task<IEnumerable<WorkflowInstance>> FindInstancesAsync(WorkflowQuery query);
}
๐ฏ Use Cases
Order Processing & Checkout: Sequential validation, payment, invoice generation.
User Onboarding: Multiple screens, decision logic, permission requests.
Document Approval: Parallel reviewer branches, approval/rejection logic.
Business Processes: Complex workflows with events, compensation, and retries.
โ Benefits
Flexibility: Modify workflows without changing code.
Visibility: Track progress and errors in real-time.
Reusability: Encapsulate business logic in activities.
Resilience: Retry, compensation, and error handling.
Scalability: Parallel branches, complex conditional flows.
๐ References
Inspired by BPMN and workflow engines like Elsa Workflows
Compatible with .NET MAUI, .NET 8, and console apps
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
-
net8.0
- Microsoft.Extensions.Logging (>= 9.0.9)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 1.0.0 | 179 | 10/24/2025 |