Skip to content

Commit 4f335a4

Browse files
Copilotsfmskywalker
andcommitted
Fix code review feedback: complete method signatures, correct activity names, add missing using statements
Co-authored-by: sfmskywalker <938393+sfmskywalker@users.noreply.github.com>
1 parent b439e72 commit 4f335a4

1 file changed

Lines changed: 37 additions & 16 deletions

File tree

extensibility/custom-activities.md

Lines changed: 37 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -757,24 +757,40 @@ public class ProcessOrder : CodeActivity
757757
Use `GetService<T>()` instead of `GetRequiredService<T>()` when a service is optional:
758758

759759
```csharp
760-
protected override async ValueTask ExecuteAsync(ActivityExecutionContext context)
760+
using Elsa.Workflows;
761+
using Elsa.Workflows.Models;
762+
763+
public class GetDataActivity : CodeActivity
761764
{
762-
// Optional service - returns null if not registered
763-
var cacheService = context.GetService<ICacheService>();
764-
765-
if (cacheService != null)
765+
[Input(Description = "Data key")]
766+
public Input<string> Key { get; set; } = default!;
767+
768+
[Output(Description = "Retrieved data")]
769+
public Output<string> Data { get; set; } = default!;
770+
771+
protected override async ValueTask ExecuteAsync(ActivityExecutionContext context)
766772
{
767-
// Use cache if available
768-
var cachedData = await cacheService.GetAsync(key);
769-
if (cachedData != null)
773+
var key = Key.Get(context);
774+
775+
// Optional service - returns null if not registered
776+
var cacheService = context.GetService<ICacheService>();
777+
778+
if (cacheService != null)
770779
{
771-
return cachedData;
780+
// Use cache if available
781+
var cachedData = await cacheService.GetAsync(key);
782+
if (cachedData != null)
783+
{
784+
Data.Set(context, cachedData);
785+
return;
786+
}
772787
}
788+
789+
// Fallback to direct data access
790+
var dataService = context.GetRequiredService<IDataService>();
791+
var data = await dataService.GetAsync(key);
792+
Data.Set(context, data);
773793
}
774-
775-
// Fallback to direct data access
776-
var dataService = context.GetRequiredService<IDataService>();
777-
return await dataService.GetAsync(key);
778794
}
779795
```
780796

@@ -1062,6 +1078,7 @@ public class OrderEventWorkflow : WorkflowBase
10621078
{
10631079
new CustomEventTrigger
10641080
{
1081+
Id = "CustomEventTrigger1",
10651082
EventName = new("OrderPlaced"),
10661083
CanStartWorkflow = true // Critical: enables trigger functionality
10671084
},
@@ -1134,6 +1151,7 @@ using Elsa.Extensions;
11341151
using Elsa.Workflows;
11351152
using Elsa.Workflows.Attributes;
11361153
using Elsa.Workflows.Models;
1154+
using Elsa.Workflows.UIHints;
11371155

11381156
[Activity("MyCompany", "HTTP", "Wait for incoming webhook")]
11391157
public class WebhookTrigger : Trigger
@@ -1488,7 +1506,7 @@ public class OpenApiActivityProvider : IActivityProvider
14881506
Description = operation.Value.Description,
14891507
Constructor = context =>
14901508
{
1491-
var activity = _activityFactory.Create<HttpRequestActivity>(context);
1509+
var activity = _activityFactory.Create<SendHttpRequest>(context);
14921510
activity.Method = new(operation.Key.ToString());
14931511
activity.Url = new(path.Key);
14941512
activity.Type = typeName;
@@ -1514,8 +1532,11 @@ builder.Services.AddElsa(elsa =>
15141532
{
15151533
// Register the activity provider
15161534
elsa.AddActivityProvider<ProductActivityProvider>();
1517-
1518-
// Or register multiple providers
1535+
});
1536+
1537+
// Or register multiple providers
1538+
builder.Services.AddElsa(elsa =>
1539+
{
15191540
elsa.AddActivityProvider<ProductActivityProvider>();
15201541
elsa.AddActivityProvider<OpenApiActivityProvider>();
15211542
});

0 commit comments

Comments
 (0)