Skip to content

Conversation

@kshyju
Copy link
Member

@kshyju kshyju commented Jan 22, 2026

Summary

Adding GetFunctionContext extension method on TaskOrchestrationContext. This returns the FunctionsContext instance if the orchestrationcontext is running in Functions hosting context.

Why is this change needed?

We need to retrieve a registered dependency from the DI container. This can be done via the InstanceServices property on FunctionContext. The AddOrchestratorFunc is used to register the orchestration to support scenarios where we override the function executor with our custom executor. In those cases, the TaskOrchestrationContext parameter fails to bind when used as a function input parameter (because that binding happens in the DurableFunctionExecutor), particularly for Microsoft Agent Framework support scenarios.

functionApplicationBuilder.ConfigureDurableWorker().AddTasks(tasks =>
{
    tasks.AddOrchestratorFunc<string, string>(
        "MyCustomOrchestration",
        async (orchestrationContext, request) =>
        {
            FunctionContext functionContext = orchestrationContext.GetFunctionContext()
                ?? throw new InvalidOperationException("FunctionContext is not available!.");

            var runner = functionContext.InstanceServices.GetRequiredService<DurableWorkflowRunner>();
            ILogger logger = orchestrationContext.CreateReplaySafeLogger("MyCustomOrchestration");

            return await runner.RunWorkflowOrchestrationAsync(orchestrationContext, request, logger);
        });
});

Issues / work items

n/a


Project checklist

  • Documentation changes are not required
    • Otherwise: Documentation PR is ready to merge and referenced in pending_docs.md
  • Release notes are not required for the next release
    • Otherwise: Notes added to release_notes.md
  • Backport is not required
    • Otherwise: Backport tracked by issue/PR #issue_or_pr
  • All required tests have been added/updated (unit tests, E2E tests)
  • No extra work is required to be leveraged by OutOfProc SDKs
    • Otherwise: Work tracked here: #issue_or_pr_in_each_sdk
  • No change to the version of the WebJobs.Extensions.DurableTask package
    • Otherwise: Major/minor updates are reflected in /src/Worker.Extensions.DurableTask/AssemblyInfo.cs
  • No EventIds were added to EventSource logs
  • This change should be added to the v2.x branch
    • Otherwise: This change applies exclusively to WebJobs.Extensions.DurableTask v3.x and will be retained only in the dev and main branches
  • Breaking change?
    • If yes:
      • Impact:
      • Migration guidance:

AI-assisted code disclosure (required)

Was an AI tool used? (select one)

  • No
  • Yes, AI helped write parts of this PR (e.g., GitHub Copilot)
  • Yes, an AI agent generated most of this PR

If AI was used:

  • Tool(s):
  • AI-assisted areas/files:
  • What you changed after AI output:

AI verification (required if AI was used):

  • I understand the code and can explain it
  • I verified referenced APIs/types exist and are correct
  • I reviewed edge cases/failure paths (timeouts, retries, cancellation, exceptions)
  • I reviewed concurrency/async behavior
  • I checked for unintended breaking or behavior changes

Testing

Automated tests

  • Result: Passed / Failed (link logs if failed)

Manual validation (only if runtime/behavior changed)

  • Environment (OS, .NET version, components):
  • Steps + observed results:
    1.
    2.
    3.
  • Evidence (optional):

Notes for reviewers

  • N/A

Copilot AI review requested due to automatic review settings January 22, 2026 18:38
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Adds a GetFunctionContext extension method on TaskOrchestrationContext to allow orchestrator code to access the underlying Azure Functions FunctionContext (when running under Functions hosting), enabling DI access via FunctionContext.InstanceServices.

Changes:

  • Add TaskOrchestrationContext.GetFunctionContext() extension method that returns the backing FunctionContext when available.
  • Expose the backing FunctionContext from FunctionsOrchestrationContext for internal consumption by the extension method.
  • Add unit tests and bump package patch version + release notes entry.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated no comments.

Show a summary per file
File Description
test/Worker.Extensions.DurableTask.Tests/TaskOrchestrationContextExtensionMethodsTests.cs Adds unit tests covering null input, Functions-backed context, and non-Functions context behavior.
src/Worker.Extensions.DurableTask/Worker.Extensions.DurableTask.csproj Bumps package version to 1.13.2 to ship the new API.
src/Worker.Extensions.DurableTask/TaskOrchestrationContextExtensionMethods.cs Implements GetFunctionContext() extension method returning FunctionContext?.
src/Worker.Extensions.DurableTask/FunctionsOrchestrationContext.cs Adds internal FunctionContext accessor used by the new extension method.
release_notes.md Documents the new extension method under “New Features”.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@kshyju kshyju marked this pull request as ready for review January 22, 2026 20:45

<!-- Version information -->
<VersionPrefix>1.13.1</VersionPrefix>
<VersionPrefix>1.13.2</VersionPrefix>
Copy link
Member

Choose a reason for hiding this comment

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

Since this is a new public API, should we bump the minor version instead?

Copy link
Member Author

Choose a reason for hiding this comment

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

Bumped minor version instead of patch, in the new iteration pushed.

@torosent torosent merged commit 2e59000 into dev Jan 27, 2026
22 checks passed
@torosent torosent deleted the shkr/maf-workflow-support branch January 27, 2026 17:26
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