Skip to content

Get started

Get a durable workflow running in about five minutes, using nothing but your app and a Postgres connection string.

Terminal window
dotnet add package PgWorkflows

Point the builder at your Postgres connection string and register your workflows and activities. The hosted worker is configured for you.

builder.Services.AddPgWorkflows(pg =>
pg.UsePostgres(connectionString)
.AddWorkflow<GreetingWorkflow>()
.AddActivities<HelloActivities>()
);

A workflow is an ordinary C# class; activities hold the side effects.

[Workflow("greeting")]
public sealed class GreetingWorkflow
{
[WorkflowRun]
public async ValueTask<string> RunAsync(
IWorkflowContext ctx,
string name,
CancellationToken cancellationToken
)
{
return await ctx.Activity(
(HelloActivities a) => a.Hello(name),
cancellationToken
);
}
}
public sealed class HelloActivities
{
[Activity("hello")]
public string Hello(string name) => $"Hello, {name}!";
}
var workflows = app.Services.GetRequiredService<IPgWorkflowClient>();
var result = await workflows.ExecuteAsync<GreetingWorkflow, string, string>("Postgres");