Adds activity host registration support#7172
Merged
sfmskywalker merged 18 commits intorelease/3.6.0from Dec 27, 2025
Merged
Conversation
Introduced new APIs and updates to enable registering custom activity hosts in the workflow management system. This includes modifications to attributes, service registrations, and extensions to streamline integration for advanced activity hosting scenarios.
Introduce new APIs to enable activity registration from public async methods (Task/Task<T>) on CLR types. Includes `HostMethodActivitiesOptions`, `HostMethodActivity`, `HostMethodActivityProvider`, and `HostMethodActivityDescriber` for dynamic activity generation and execution.
Reworked `HostMethodActivity` to support resumable workflows, improved parameter handling with pluggable value providers, and removed obsolete `AgentExecutionContext`. Enhanced method resolution, async handling, and input/output descriptor logic for better flexibility and maintainability.
…dd `GenerateBookmarkTriggerToken` method, and enhance maintainability.
…lue providers Introduced `IHostMethodParameterValueProvider` interface for custom parameter resolution, along with `DefaultHostMethodParameterValueProvider`, `DelegateHostMethodParameterValueProvider`, and `FromServicesAttribute` for flexible binding options. Enhances host method activity execution by supporting DI resolution and workflow input handling.
Updated null assignment for consistency across files and refined logic for detecting and handling newly added bookmarks. Adjusted method signatures and parameters in the DecoratedStoryWriterAgent class for more explicit input handling. These changes enhance code readability, maintainability, and robustness.
Contributor
There was a problem hiding this comment.
Pull request overview
This PR introduces a code-first activity generation system that allows developers to register CLR types whose public methods are automatically exposed as workflow activities. The main addition is the HostMethodActivity infrastructure that dynamically invokes methods on host types and manages their inputs/outputs.
- Adds
HostMethodActivityas the core runtime activity that executes methods on registered host types - Implements activity descriptor generation via
HostMethodActivityDescriberandHostMethodActivityProvider - Converts
Bookmarkfrom immutable record to mutable class to support callback metadata modification - Refactors
BookmarkExecutionContextExtensionsto use C# 13.0 extension member syntax
Reviewed changes
Copilot reviewed 19 out of 19 changed files in this pull request and generated 14 comments.
Show a summary per file
| File | Description |
|---|---|
| BackgroundActivityInvokerMiddleware.cs | Changes default to null for nullable delegate assignments for better clarity |
| HostMethodActivityDescriber.cs | New service that generates activity descriptors from host type methods using reflection |
| DelegateHostMethodParameterValueProvider.cs | New convenience wrapper for custom parameter value resolution logic |
| DefaultHostMethodParameterValueProvider.cs | New default implementation for resolving method parameters from workflow inputs or DI |
| DefaultExpressionDescriptorProvider.cs | Removes unused System.Diagnostics using statement |
| HostMethodActivitiesOptions.cs | New options class for registering host types to expose as activities |
| WorkflowManagementFeature.cs | Adds AddActivityHost methods and registers host method services |
| CachingWorkflowDefinitionsFeature.cs | Removes unused Elsa.Workflows.Management.Handlers using statement |
| WorkflowInstanceStoreExtensions.cs | Removes unused Elsa.Workflows.Management.Filters using statement |
| ModuleExtensions.cs | Adds convenience AddActivityHost extension method for module configuration |
| IHostMethodParameterValueProvider.cs | New interface and context types for extensible parameter value resolution |
| IHostMethodActivityDescriber.cs | New interface for describing host method activities |
| FromServicesAttribute.cs | New attribute to mark parameters for DI resolution instead of workflow inputs |
| HostMethodActivityProvider.cs | New activity provider that exposes host type methods as workflow activities |
| HostMethodActivity.cs | New runtime activity that invokes host type methods and manages bookmark callbacks |
| Bookmark.cs | Converts from immutable record to mutable class with init properties to allow metadata modification |
| InputAttribute.cs | Extends targets to include Method and ReturnValue for host method scenarios |
| ActivityAttribute.cs | Extends targets to include Struct and Interface for broader host type support |
| BookmarkExecutionContextExtensions.cs | Refactors to use C# 13.0 extension member syntax for better organization |
src/modules/Elsa.Workflows.Management/Activities/CodeFirst/HostMethodActivityProvider.cs
Outdated
Show resolved
Hide resolved
src/modules/Elsa.Workflows.Management/Activities/CodeFirst/HostMethodActivity.cs
Outdated
Show resolved
Hide resolved
src/modules/Elsa.Workflows.Management/Activities/HostMethod/HostMethodActivity.cs
Show resolved
Hide resolved
src/modules/Elsa.Workflows.Management/Features/WorkflowManagementFeature.cs
Outdated
Show resolved
Hide resolved
src/modules/Elsa.Workflows.Management/Contracts/IHostMethodActivityDescriber.cs
Show resolved
Hide resolved
src/modules/Elsa.Workflows.Management/Activities/HostMethod/HostMethodActivity.cs
Show resolved
Hide resolved
src/modules/Elsa.Workflows.Management/Services/HostMethodActivityDescriber.cs
Show resolved
Hide resolved
src/modules/Elsa.Workflows.Management/Services/HostMethodActivityDescriber.cs
Show resolved
Hide resolved
src/modules/Elsa.Workflows.Management/Activities/HostMethod/HostMethodActivity.cs
Show resolved
Hide resolved
src/modules/Elsa.Workflows.Runtime/Middleware/Activities/BackgroundActivityInvokerMiddleware.cs
Show resolved
Hide resolved
…tMethodActivityProvider.cs Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
…entFeature.cs Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
…ivityDescriber.cs Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
…nd align with updated activity execution logic. Enhance DI-based parameter resolution and update XML documentation for `HostMethodActivitiesOptions`.
… in Elsa pipeline
…gister `TestHostMethod` as an activity host in the workflow server.
sfmskywalker
added a commit
that referenced
this pull request
Feb 7, 2026
* Add support for activity host registration across workflows Introduced new APIs and updates to enable registering custom activity hosts in the workflow management system. This includes modifications to attributes, service registrations, and extensions to streamline integration for advanced activity hosting scenarios. * Remove unused `using` directives across Workflow Management module * Add support for host method activity registration and description Introduce new APIs to enable activity registration from public async methods (Task/Task<T>) on CLR types. Includes `HostMethodActivitiesOptions`, `HostMethodActivity`, `HostMethodActivityProvider`, and `HostMethodActivityDescriber` for dynamic activity generation and execution. * Refactor host method activity execution and cleanup. Reworked `HostMethodActivity` to support resumable workflows, improved parameter handling with pluggable value providers, and removed obsolete `AgentExecutionContext`. Enhanced method resolution, async handling, and input/output descriptor logic for better flexibility and maintainability. * Refactor `Bookmark` model to use mutable properties and update XML documentation. * Refactor `BookmarkExecutionContextExtensions` to improve structure, add `GenerateBookmarkTriggerToken` method, and enhance maintainability. * Add extensibility for host method parameter binding with pluggable value providers Introduced `IHostMethodParameterValueProvider` interface for custom parameter resolution, along with `DefaultHostMethodParameterValueProvider`, `DelegateHostMethodParameterValueProvider`, and `FromServicesAttribute` for flexible binding options. Enhances host method activity execution by supporting DI resolution and workflow input handling. * Refactor nullable usage and improve bookmark management logic Updated null assignment for consistency across files and refined logic for detecting and handling newly added bookmarks. Adjusted method signatures and parameters in the DecoratedStoryWriterAgent class for more explicit input handling. These changes enhance code readability, maintainability, and robustness. * Update src/modules/Elsa.Workflows.Management/Activities/CodeFirst/HostMethodActivityProvider.cs Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Ensure `CallbackMethodName` is set and skip bookmarks with empty values * Update src/modules/Elsa.Workflows.Management/Features/WorkflowManagementFeature.cs Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Update src/modules/Elsa.Workflows.Management/Contracts/IHostMethodActivityDescriber.cs Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Update src/modules/Elsa.Workflows.Core/Attributes/InputAttribute.cs Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Refactor `CodeFirst` namespace to `HostMethod` for improved clarity and align with updated activity execution logic. Enhance DI-based parameter resolution and update XML documentation for `HostMethodActivitiesOptions`. * Add `Penguin` activity host with sample activity methods and register in Elsa pipeline * Add `TestHostMethod` activities and corresponding component tests. Register `TestHostMethod` as an activity host in the workflow server. --------- Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
This was referenced Mar 5, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Adds support for registering activity hosts, enabling code-first activity generation from CLR types.
HostMethodActivityto execute public async methods on CLR types.HostMethodActivityProviderto provide activity descriptors for configured host methods.IHostMethodActivityDescriberto describe host method activities.FromServicesAttributeto resolve host method parameters from the service provider.BookmarkExecutionContextExtensionsand theBookmarkmodel to improve bookmark management logic and structure.This allows developers to register classes whose methods will be automatically exposed as activities in the workflow designer.
This change is