elsa-workflows / elsa-workflows/elsa-core

[ENH] allow Trigger name to be configured independently from Activity name, to allow creation of custom Event Triggers

Open
#5,731 1 comment 0 reactions 0 assignees View on GitHub
enhancement triaged
Dominant language
C#
Stars
7.9k
Forks
1.5k
Avg merge
15h 22m
Merged PRs (30d)
114

Description

### Enhancement Overview
Currently it is problematic to create custom activities inherited from `Elsa.Workflows.Runtime.Activities.Event`, because events (ex-signals) raised by `PublishEvent` activity will not get those custom activities triggered by default.

This happens because when the trigger for a custom activity is registered in the database, the "Name" column will be assigned the name of a class itself, e.g., "My.CustomActivity", which technically comes from `IActivity.Type`. At the same time, `PublishEvent` mechanism queries database for registered triggers with the name "Elsa.Event".

Although `IActivity.Type` for a custom activity could be changed to "Elsa.Event", this results in severe side effects, and generally feels like a hack.

### Proposed Enhancement
The proposal is to make changes which would allow extension of `Elsa.Workflows.Runtime.Activities.Event` activity, while at the same time allowing such extended activities to be triggered by "standard" `PublishEvent`.

Suggested solution is to extend `ITrigger` interface with `TriggerName` field, which would default to `IActivity.Type`, but could be customized if needed. Then `ITrigger.TriggerName` could be used instead of `IActivity.Type` by `TriggerIndexer` when registering trigger in the DB.

That way it would be possible make custom activities to use the name "Elsa.Event" during trigger registration (hence `PublishEvent` could trigger them), while maintaining "proper" `IActivity.Type` for all other purposes.

In other words, the solution might look something like this:
```csharp

public interface ITrigger : IActivity
{
...
string TriggerName => this.Type;
}

public class TriggerIndexer : ITriggerIndexer
{
...
private async Task> CreateWorkflowTriggersAsync(WorkflowIndexingContext context, ITrigger trigger)
{
...
// used to be: var triggerTypeName = trigger.Type;
var triggerTypeName = trigger.TriggerName;
...
}
}

public class MyCustomEvent : Trigger, ITrigger
{
...
// Allow MyCustomEvent to be triggered by PublishEvent
string ITrigger.TriggerName => "Elsa.Event";
...
}
```

### Background
Our scenario involves providing Elsa Studio's interface to our customers, where they can create workflows for their business processes. To make things user-friendly for non-technical users, we plan to hide some more technical aspects of the Studio, and to provide numerous custom activities which our customers can easily understand. Among these custom activities there will be user-friendly versions for Event activity, which will allow to build event (signal) name by selecting values from dropdowns and other means, instead of manually typing in the event (signal) name.

### Alternative Solutions
None that I can think of given my current understanding of Elsa's codebase.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.