Skip to content

Adds activity host registration support#7172

Merged
sfmskywalker merged 18 commits intorelease/3.6.0from
feat/activity-host
Dec 27, 2025
Merged

Adds activity host registration support#7172
sfmskywalker merged 18 commits intorelease/3.6.0from
feat/activity-host

Conversation

@sfmskywalker
Copy link
Member

@sfmskywalker sfmskywalker commented Dec 27, 2025

Adds support for registering activity hosts, enabling code-first activity generation from CLR types.

  • Introduces HostMethodActivity to execute public async methods on CLR types.
  • Implements HostMethodActivityProvider to provide activity descriptors for configured host methods.
  • Creates IHostMethodActivityDescriber to describe host method activities.
  • Adds FromServicesAttribute to resolve host method parameters from the service provider.
  • Updates BookmarkExecutionContextExtensions and the Bookmark model 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 Reviewable

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.
Copilot AI review requested due to automatic review settings December 27, 2025 10:59
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

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 HostMethodActivity as the core runtime activity that executes methods on registered host types
  • Implements activity descriptor generation via HostMethodActivityDescriber and HostMethodActivityProvider
  • Converts Bookmark from immutable record to mutable class to support callback metadata modification
  • Refactors BookmarkExecutionContextExtensions to 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

sfmskywalker and others added 10 commits December 27, 2025 19:38
…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`.
…gister `TestHostMethod` as an activity host in the workflow server.
@sfmskywalker sfmskywalker merged commit fa04e1e into release/3.6.0 Dec 27, 2025
2 of 3 checks passed
@sfmskywalker sfmskywalker deleted the feat/activity-host branch December 27, 2025 19:52
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>
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.

2 participants