elsa-core/samples/Sample02/Program.cs
2019-09-17 16:32:09 +02:00

39 lines
1.3 KiB
C#

using System;
using System.Threading.Tasks;
using Elsa.Activities.Console.Activities;
using Elsa.Activities.Console.Extensions;
using Elsa.Expressions;
using Elsa.Extensions;
using Elsa.Services;
using Microsoft.Extensions.DependencyInjection;
namespace Sample02
{
/// <summary>
/// A minimal workflows program defined in code using fluent workflow builder and Console activities.
/// </summary>
class Program
{
static async Task Main(string[] args)
{
// Setup a service collection.
var services = new ServiceCollection()
.AddWorkflows()
.AddConsoleActivities()
.BuildServiceProvider();
// Define a workflow.
var workflowBuilder = services.GetRequiredService<IWorkflowBuilder>();
var workflowDefinition = workflowBuilder
.StartWith<WriteLine>(x => x.TextExpression = new LiteralExpression("Hello world!"))
.Then<WriteLine>(x => x.TextExpression = new LiteralExpression("Goodbye cruel world..."))
.Build();
// Start the workflow.
var invoker = services.GetService<IWorkflowInvoker>();
await invoker.StartAsync(workflowDefinition);
Console.ReadLine();
}
}
}