using System; using System.Threading.Tasks; using Elsa.Persistence; using Elsa.Persistence.EntityFramework.Core.Extensions; using Elsa.Persistence.EntityFramework.Sqlite; using Elsa.Persistence.Specifications.WorkflowInstances; using Elsa.Services; using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.DependencyInjection; namespace Elsa.Samples.Persistence.EntityFramework { class Program { private static async Task Main() { // Create a service container with Elsa services. var services = new ServiceCollection() .AddElsa(options => options // Configure Elsa to use the Entity Framework Core persistence provider using Sqlite. .UseEntityFrameworkPersistence(ef => ef.UseSqlite()) .AddConsoleActivities() .AddWorkflow()) .AddAutoMapperProfiles() .BuildServiceProvider(); // Run startup actions (not needed when registering Elsa with a Host). var startupRunner = services.GetRequiredService(); await startupRunner.StartupAsync(); // Get a workflow runner. var workflowRunner = services.GetRequiredService(); // Run the workflow. var workflowInstance = await workflowRunner.RunWorkflowAsync(); // Get a reference to the workflow instance store. var store = services.GetRequiredService(); // Count the number of workflow instances of HelloWorld. var count = await store.CountAsync(new WorkflowDefinitionIdSpecification(nameof(HelloWorld))); Console.WriteLine(count); var loadedWorkflowInstance = await store.FindByIdAsync(workflowInstance.Id); Console.WriteLine(loadedWorkflowInstance); } } }