elsa-core/samples/Sample05/Program.cs

51 lines
1.6 KiB
C#
Raw Normal View History

2019-07-22 16:55:02 +00:00
using System;
using System.Threading.Tasks;
using Elsa.Activities.Console.Extensions;
using Elsa.Activities.Timers.Extensions;
using Elsa.Extensions;
using Elsa.Persistence.Memory;
2019-07-22 16:55:02 +00:00
using Elsa.Services;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
using NodaTime;
namespace Sample05
{
/// <summary>
/// A minimal workflows program defined in code with a strongly-typed workflow class.
/// </summary>
class Program
{
static async Task Main()
{
var host = new HostBuilder()
.ConfigureServices(ConfigureServices)
.ConfigureLogging(logging => logging.AddConsole())
.UseConsoleLifetime()
.Build();
using (host)
{
SetupWorkflow(host.Services);
await host.StartAsync();
2019-07-22 16:55:02 +00:00
await host.WaitForShutdownAsync();
}
}
private static void SetupWorkflow(IServiceProvider services)
{
// Register the workflow.
var registry = services.GetService<IWorkflowRegistry>();
registry.RegisterWorkflow<RecurringWorkflow>();
}
private static void ConfigureServices(IServiceCollection services)
{
services
.AddWorkflows()
.AddConsoleActivities()
2019-09-17 14:32:09 +00:00
.AddTimerActivities(options => options.Configure(x => x.SweepInterval = Period.FromSeconds(1)));
2019-07-22 16:55:02 +00:00
}
}
}