Skip to content

Workflows & activities

Workflows orchestrate; activities do. The workflow method describes the durable control flow, while every side effect — HTTP calls, emails, database writes — lives in an activity so it can be retried and recorded exactly once.

[Workflow("greeting")]
public sealed class GreetingWorkflow
{
[WorkflowRun]
public async ValueTask<string> RunAsync(
IWorkflowContext ctx,
string name,
CancellationToken cancellationToken
)
{
// ...
}
}
public sealed class EmailActivities
{
[Activity("send-welcome")]
public string SendWelcome(string email)
{
// side effects go here
}
}
var receipt = await ctx.Activity(
(PaymentActivities a) => a.Charge(input.UserName, input.Amount),
cancellationToken
);
builder.Services.AddPgWorkflows(pg =>
pg.UsePostgres(connectionString)
.AddWorkflow<GreetingWorkflow>()
.AddActivities<EmailActivities>()
);