Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Dec 10, 2025

Enables compile-time type-safe external event handling through source-generated extension methods.

Changes

  • DurableEventAttribute: New attribute for annotating event types (classes/records/structs)
  • Source Generator: Extended to detect DurableEventAttribute and generate WaitFor{EventName}Async extension methods on TaskOrchestrationContext
  • Tests: Added unit tests covering records, classes, and namespaced event types
  • Sample: EventsSample project demonstrating approval and data processing workflows

Usage

Define an event:

[DurableEvent(nameof(ApprovalEvent))]
public sealed record ApprovalEvent(bool Approved, string? Approver);

Generated extension method:

public static Task<ApprovalEvent> WaitForApprovalEventAsync(
    this TaskOrchestrationContext context, 
    CancellationToken cancellationToken = default)

Use in orchestrator:

// Before: string literal and explicit generic type
ApprovalEvent approval = await context.WaitForExternalEvent<ApprovalEvent>("ApprovalEvent");

// After: strongly-typed method with IntelliSense
ApprovalEvent approval = await context.WaitForApprovalEventAsync();

Attribute supports custom event names: [DurableEvent("CustomName")]

Original prompt

This section details on the original issue you should resolve

<issue_title>Strongly-typed events</issue_title>
<issue_description>It would be nice to have methods for external events generated the same way we get orchestrations and activities added to TaskOrchestrationContext.

Example: If I define below type and annotate it with the (proposed) DurableEventAttribute

[DurableEvent(nameof(ApprovalEvent))]
public sealed record ApprovalEvent(bool Approved, string? Approver);

The generator should generate the following extension method:

var approvalResult = await context.WaitForApprovalEvent(); // approvalResult is of type ApprovalEvent

</issue_description>

Comments on the Issue (you are @copilot in this section)


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Comment on lines +23 to +30
if (approvalEvent.Approved)
{
return $"Request '{requestName}' was approved by {approvalEvent.Approver ?? "unknown"}";
}
else
{
return $"Request '{requestName}' was rejected by {approvalEvent.Approver ?? "unknown"}";
}
Copilot AI changed the title [WIP] Add strongly-typed events support in TaskOrchestrationContext Add strongly-typed external events with DurableEventAttribute Dec 10, 2025
Copilot AI requested a review from YunchuWang December 10, 2025 19:06
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.

Strongly-typed events

2 participants