ProtonFlow.Persistence.EfCore 0.0.1

dotnet add package ProtonFlow.Persistence.EfCore --version 0.0.1
                    
NuGet\Install-Package ProtonFlow.Persistence.EfCore -Version 0.0.1
                    
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="ProtonFlow.Persistence.EfCore" Version="0.0.1" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="ProtonFlow.Persistence.EfCore" Version="0.0.1" />
                    
Directory.Packages.props
<PackageReference Include="ProtonFlow.Persistence.EfCore" />
                    
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 ProtonFlow.Persistence.EfCore --version 0.0.1
                    
#r "nuget: ProtonFlow.Persistence.EfCore, 0.0.1"
                    
#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 ProtonFlow.Persistence.EfCore@0.0.1
                    
#: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=ProtonFlow.Persistence.EfCore&version=0.0.1
                    
Install as a Cake Addin
#tool nuget:?package=ProtonFlow.Persistence.EfCore&version=0.0.1
                    
Install as a Cake Tool

ProtonFlow.Persistence.EfCore

Entity Framework Core based persistence provider for the ProtonFlow BPMN Engine.

This package adds durable storage for:

  • Process Definitions (versioned deployments)
  • Process Instances (variables, tokens, lifecycle status)
  • Step Execution History (per element metrics)
  • KPI Aggregation (dynamic query of durations, counts)
  • Instance Notes (lightweight audit / annotations)

The core ProtonFlow.BpmnEngine remains storage-agnostic; you can still use the in?memory provider for tests or prototypes. Add this package when you need durability or analytics.

Quick Start

  1. Install packages:
dotnet add package ProtonFlow.BpmnEngine

dotnet add package ProtonFlow.Persistence.EfCore
  1. Configure the engine with EF Core:
using BpmnEngine.Engine;
using Microsoft.EntityFrameworkCore;
using ProtonFlow.Persistence.EfCore.Extensions; // UseEntityFramework

var engine = BpmnEngineBuilder.Create()
    .UseEntityFramework(opt => opt.UseSqlite("Data Source=protonflow.db"))
    .AddTaskHandler("rest-call", async ctx => { /* your handler */ })
    .Build();
  1. Deploy and run a process:
var xml = """
<?xml version="1.0"?>
<definitions xmlns="http://www.omg.org/spec/BPMN/20100524/MODEL">
  <process id="demo" name="Demo Process">
    <startEvent id="start" />
    <sequenceFlow id="f1" sourceRef="start" targetRef="task" />
    <serviceTask id="task" implementation="rest-call" />
    <sequenceFlow id="f2" sourceRef="task" targetRef="end" />
    <endEvent id="end" />
  </process>
</definitions>
""";

var def = await engine.LoadBpmnXml(xml);
var instance = await engine.StartProcessAsync(def.Key, new { amount = 500 });
while (await engine.CanStepAsync(instance.Id))
{
    await engine.StepAsync(instance.Id);
}
  1. Query active token positions:
var positions = await engine.GetCurrentTokenPositions(instance.Id);

Switching Between InMemory and EF Core

  • InMemory (no persistence):
var engine = BpmnEngineBuilder.Create()
    .UseInMemory()
    .Build();
  • EF Core (durable):
var engine = BpmnEngineBuilder.Create()
    .UseEntityFramework(o => o.UseSqlite("Data Source=protonflow.db"))
    .Build();

You can register different providers (SqlServer, PostgreSQL, InMemory) by changing the UseXxx call.

Unified Storage Abstraction

The EF implementation provides IBpmnStorage for richer operations (definitions, instances, steps, KPIs, status changes, notes). Engine compatibility is maintained through adapters implementing existing IProcessStore and IInstanceStore.

Key query objects:

var instances = await storage.QueryProcessInstancesAsync(new ProcessInstanceQuery
{
    ProcessKey = "demo",
    Statuses = new[] { ProcessInstanceStatus.Running },
    Take = 50
});

var kpis = await storage.QueryStepKpisAsync(new StepKpiQuery
{
    ProcessKey = "demo",
    GroupBy = KpiGroupBy.ProcessAndElement
});

KPI Aggregation

QueryStepKpisAsync dynamically aggregates over completed step executions (count, min, max, average duration) grouped by process, element, or both.

Status Transitions

Use:

await storage.MarkInstanceCancelledAsync(instanceId, "User cancelled", DateTime.UtcNow);
await storage.MarkInstanceFailedAsync(instanceId, "Timeout", DateTime.UtcNow);

Lifecycle timestamps (Started / Completed / Cancelled / Failed) are tracked for audit and SLA metrics.

Instance Notes

Add ad-hoc annotations:

await storage.AddInstanceNoteAsync(new InstanceNote
{
    InstanceId = instanceId,
    Type = "Audit",
    Message = "Manual approval granted"
});

Testing

All components are designed for unit & integration tests:

  • Use SQLite in-memory for relational fidelity:
var conn = new SqliteConnection("Filename=:memory:");
await conn.OpenAsync();
var options = new DbContextOptionsBuilder<ProtonFlowDbContext>()
    .UseSqlite(conn)
    .Options;
  • Use EF Core InMemory provider for lightweight logic tests.

Extensibility Roadmap

Future additions can introduce:

  • Timer events (add TimerEventRecord table)
  • Message subscriptions / correlations
  • Audit log table (structured events)
  • Aggregated daily/hourly KPI snapshot tables
  • Multi-tenancy (add TenantId + composite indexes)

The current schema & interfaces are intentionally open for these without breaking changes.

License

MIT

Repository

https://github.com/peterwidmer/ProtonFlow

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
0.0.1 139 9/11/2025