elsa-core/src/samples/Elsa.Samples.HelloWorldConsole/Program.cs

43 lines
1.5 KiB
C#
Raw Normal View History

2020-02-18 21:29:44 +00:00
using System;
using System.Threading.Tasks;
using Elsa.Activities.Console;
using Elsa.Builders;
2020-10-10 19:10:09 +00:00
using Elsa.Runtime;
2020-02-18 21:29:44 +00:00
using Elsa.Services;
using Microsoft.Extensions.DependencyInjection;
2020-10-10 19:10:09 +00:00
using YesSql.Provider.Sqlite;
2020-02-18 21:29:44 +00:00
namespace Elsa.Samples.HelloWorldConsole
{
class Program
{
static async Task Main(string[] args)
{
// Create a service container with Elsa services.
var services = new ServiceCollection()
2020-10-10 19:10:09 +00:00
//.AddElsa(options => options.UsePersistence(config => config.UseSqLite("Data Source=elsa.db;Cache=Shared")))
2020-02-18 21:29:44 +00:00
.AddElsa()
.AddConsoleActivities()
.AddSingleton(Console.In)
.BuildServiceProvider();
2020-10-10 19:10:09 +00:00
// Run startup actions (not needed when registering Elsa with a Host).
var startupRunner = services.GetRequiredService<IStartupRunner>();
await startupRunner.StartupAsync();
2020-02-18 21:29:44 +00:00
// Build a new workflow.
var workflow = services.GetService<IWorkflowBuilder>()
.WriteLine("Hello World!")
.WriteLine("What's your name?")
.ReadLine()
2020-10-03 10:48:25 +00:00
.WriteLine(context => $"Greetings, {context.Input}!")
2020-02-18 21:29:44 +00:00
.Build();
// Get the workflow host.
var workflowHost = services.GetService<IWorkflowHost>();
// Execute the workflow.
await workflowHost.RunWorkflowAsync(workflow);
}
}
}