elsa-core/src/samples/console/Elsa.Samples.HelloWorld/Program.cs

38 lines
1 KiB
C#
Raw Normal View History

using Elsa.Extensions;
using Elsa.Workflows.Core.Activities;
using Elsa.Workflows.Core.Models;
using Elsa.Workflows.Core.Services;
using Microsoft.Extensions.DependencyInjection;
// Setup service container.
var services = new ServiceCollection();
// Add Elsa services.
services.AddElsa();
// Build service container.
var serviceProvider = services.BuildServiceProvider();
// Create a workflow.
var nameVariable = new Variable<string>();
// Define a simple sequential workflow:
var workflow = new Sequence
{
// Register the name variable.
Variables = { nameVariable },
// Setup the sequence of activities to run.
Activities =
{
new WriteLine("Please tell me your name:"),
new ReadLine(nameVariable),
new WriteLine(context => $"Nice to meet you, {nameVariable.Get(context)}!")
}
};
// Resolve a workflow runner to run the workflow.
var workflowRunner = serviceProvider.GetRequiredService<IWorkflowRunner>();
// Run the workflow.
await workflowRunner.RunAsync(workflow);