elsa-workflows / elsa-core

A .NET workflows library
https://v3.elsaworkflows.io/
MIT License
5.88k stars 1.06k forks source link

[ENH] Support TypeName Overriding in IActivityDescriptorModifier Without Breaking Workflow Builder API #5263

Open sfmskywalker opened 3 weeks ago

sfmskywalker commented 3 weeks ago

Currently, the IActivityDescriptorModifier interface allows overriding various activity descriptor attributes such as Display Name, Description, Inputs, and Outputs. This is implemented before the activities are registered in the activity registry. However, attempts to override the TypeName attribute can disrupt the functioning of programmatically created workflows using the workflow builder API. This occurs because the instantiation of an activity directly relies on the ActivityAttribute.TypeName or defaults to the activity's .NET type if TypeName is not set.

To address this, we propose enhancing the handling of TypeName overrides. Specifically, we need to implement a mechanism that checks and updates the TypeName of activity instances dynamically. This approach should ensure that any changes to the TypeName through the IActivityDescriptorModifier are accurately reflected.

Expected Outcome:

This enhancement will contribute to greater flexibility in modifying and extending activities without risking the stability of programmatically created workflows.

glime-ai[bot] commented 3 weeks ago

To address the proposed enhancement, it's important to consider the current behavior of Elsa Workflows as described in the provided context. The TypeName attribute of an activity is crucial for the correct serialization and deserialization of workflow definitions, as well as for the materialization of workflow blueprints. As such, any changes to the TypeName must be handled with care to avoid disrupting existing workflows.

The IActivityDescriptorModifier interface allows for modifications to activity descriptors, which are used by the designer to present activities to the user. However, changing the TypeName through this interface could lead to inconsistencies between the descriptors and the actual .NET types used in programmatic workflows.

To implement the proposed enhancement, the following steps could be considered:

  1. Introduce a new mechanism that maps the original TypeName to the overridden TypeName. This mapping should be accessible during the workflow definition materialization process.

  2. Update the IWorkflowBlueprintMaterializer to use the new mapping mechanism to resolve the correct .NET type for an activity based on its TypeName.

  3. Ensure that the workflow builder API can handle dynamically provided activities, including those with overridden TypeName attributes. This may involve extending the API to allow specifying a TypeName when adding activities to the workflow programmatically.

  4. Provide clear documentation and guidelines on how to use the TypeName override feature to ensure that developers understand the implications and how to update their workflows accordingly.

  5. Implement thorough testing to ensure that workflows with overridden TypeName attributes function correctly and that existing workflows are not adversely affected by these changes.

By following these steps, it should be possible to allow dynamic overriding of TypeName in IActivityDescriptorModifier without breaking the integrity and functionality of workflows constructed using the workflow builder API. This enhancement would indeed contribute to greater flexibility in modifying and extending activities.

This comment was generated by Glime.