Skip to content

feat(dotnet): workflow context propagation quickstart - #1310

Closed
nelson-parente wants to merge 5 commits into
dapr:masterfrom
nelson-parente:feat/wf-ctx-propagation-dotnet
Closed

feat(dotnet): workflow context propagation quickstart#1310
nelson-parente wants to merge 5 commits into
dapr:masterfrom
nelson-parente:feat/wf-ctx-propagation-dotnet

Conversation

@nelson-parente

@nelson-parente nelson-parente commented May 19, 2026

Copy link
Copy Markdown
Contributor

Summary

Scenario

Patient intake / e-prescribing pipeline. A compliance audit and a pharmacy dispense step refuse to act unless the propagated history proves the required upstream checks (insurance, allergies, drug interactions) actually ran.

PatientIntake (root)
  └─ VerifyInsurance         (activity, no propagation)
  └─ PrescribeMedication     (child wf, HistoryPropagationScope.Lineage)
        └─ CheckAllergies                 (activity, no propagation)
        └─ ScreenDrugInteractions         (activity, no propagation)
        └─ ComplianceAudit                (grandchild wf, HistoryPropagationScope.Lineage)
        |      reads PatientIntake + PrescribeMedication events
        └─ DispenseMedicationWorkflow     (grandchild wf, HistoryPropagationScope.OwnHistory)
               reads PrescribeMedication events only
               └─ DispenseMedication       (activity)

.NET API used (from dapr/dotnet-sdk#1802)

  • HistoryPropagationScope enum: None, OwnHistory, Lineage
  • ChildWorkflowTaskOptions(PropagationScope: HistoryPropagationScope.Lineage) — passed to CallChildWorkflowAsync
  • WorkflowContext.GetPropagatedHistory()PropagatedHistory?
  • PropagatedHistory.FilterByWorkflowName(name) → filtered PropagatedHistory
  • PropagatedHistoryEntry — has WorkflowName, AppId, InstanceId, Events
  • PropagatedHistoryEvent — has EventId, Kind (HistoryEventKind), Timestamp

Key difference from the Python/Go siblings

The Python SDK and Go SDK both support a propagation argument on bare activity calls, so they call DispenseMedication as a plain activity with OWN_HISTORY. The .NET SDK v1.18 scopes HistoryPropagationScope to ChildWorkflowTaskOptions only — activity calls do not carry a propagation scope. To demonstrate identical OwnHistory trust-boundary semantics, DispenseMedicationActivity is wrapped in DispenseMedicationWorkflow (a child workflow). This is the correct .NET idiom for the v1.18 API; it is not a gap in the sample.

Replay safety

All Console.WriteLine calls inside workflows are guarded by if (!ctx.IsReplaying) so they only fire on the live execution, not on each durable replay.

Status — DRAFT

  • 7 files added, dotnet build not validated locally (dotnet SDK not on path — CI will catch compile errors)
  • Smoke-test pending Dapr 1.18 RC sidecar + Dapr.Workflow 1.18.0-rc01 on NuGet
  • Will be marked ready once: (1) Go reference dapr/go-sdk#823 merges, (2) Python sibling #1309 lands, (3) docs PR #5174 lands

Test plan

  • dotnet build clean
  • dapr run -f . against Dapr 1.18 RC sidecar with Redis
  • ComplianceAudit receives 2 propagated segments (PatientIntake + PrescribeMedication) under Lineage
  • DispenseMedicationWorkflow receives 1 propagated segment (PrescribeMedication only) under OwnHistory
  • PatientIntake segment correctly absent from DispenseMedicationWorkflow's history
  • Older sidecar (pre-1.18): GetPropagatedHistory() returns null, sample exits gracefully
  • CI passes on the .NET quickstart matrix

References

Signed-off-by: Nelson Parente <nelson_parente@live.com.pt>
Aligns the .NET workflow history propagation quickstart with the canonical
Go reference (dapr/go-sdk#823, dapr#1315) so all SDK quickstarts
share the same patient intake / e-prescribing scenario.

- Swap credit-card/fraud scenario for patient-intake/e-prescribing
- Adopt PatientIntake -> PrescribeMedication -> ComplianceAudit hierarchy
- Add IsReplaying guards around all Console.WriteLine inside workflows
- DispenseMedicationWorkflow still wraps the activity for OwnHistory
  (.NET SDK propagation is on ChildWorkflowTaskOptions only)
- Add event-level history walking in DispenseMedicationWorkflow

Signed-off-by: Nelson Parente <nelson_parente@live.com.pt>
@nelson-parente nelson-parente changed the title [DRAFT] feat(dotnet): workflow context propagation quickstart feat(dotnet): workflow context propagation quickstart May 21, 2026
@alicejgibbons

Copy link
Copy Markdown
Contributor

to be taken over by @atrauzzi

atrauzzi added 2 commits May 28, 2026 18:12

@alicejgibbons alicejgibbons left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@atrauzzi needs to be changed to 1.18 release branch and moved to the tutorials section like the other examples (Javi's java one or cassie's go one)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants