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
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Shaunebu.Common.WorkflowManager" Version="1.0.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Shaunebu.Common.WorkflowManager" Version="1.0.0" />
                    
Directory.Packages.props
<PackageReference Include="Shaunebu.Common.WorkflowManager" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Shaunebu.Common.WorkflowManager --version 1.0.0
                    
#r "nuget: Shaunebu.Common.WorkflowManager, 1.0.0"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package Shaunebu.Common.WorkflowManager@1.0.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Shaunebu.Common.WorkflowManager&version=1.0.0
                    
Install as a Cake Addin
#tool nuget:?package=Shaunebu.Common.WorkflowManager&version=1.0.0
                    
Install as a Cake Tool

NuGet Version

NET Support NET Support NET Support Support

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:

  1. Created โ€“ Workflow instance is initialized.

  2. Running โ€“ Node execution in progress.

  3. Suspended โ€“ Temporarily paused, can resume later.

  4. Cancelled โ€“ Workflow execution stopped by user or system.

  5. Completed โ€“ Successfully finished all nodes.

  6. 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 WorkflowActivity for domain-specific logic.

  • Custom Persistence โ€“ Implement IWorkflowPersistence for 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 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

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