using System; using System.IO; using Elsa.Persistence.EntityFramework.Core.Extensions; using Elsa.Providers.Workflows; using Elsa.Server.Hangfire.Extensions; using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.DependencyInjection; using Storage.Net; namespace DocumentManagement.Workflows.Extensions { public static class ServiceCollectionExtensions { public static IServiceCollection AddWorkflowServices(this IServiceCollection services, Action configureDb) { return services.AddElsa(configureDb); } private static IServiceCollection AddElsa(this IServiceCollection services, Action configureDb) { services .AddElsa(elsa => elsa // Use EF Core's SQLite provider to store workflow instances and bookmarks. .UseEntityFrameworkPersistence(configureDb) // Use Console activities for testing & demo purposes. .AddConsoleActivities() // Use Hangfire to dispatch workflows from. .UseHangfireDispatchers() // Configure Email activities. .AddEmailActivities() // Configure HTTP activities. .AddHttpActivities() ); // Get directory path to current assembly. var currentAssemblyPath = Path.GetDirectoryName(typeof(ServiceCollectionExtensions).Assembly.Location); // Configure Storage for BlobStorageWorkflowProvider with a directory on disk from where to load workflow definition JSON files from the local "Workflows" folder. services.Configure(options => options.BlobStorageFactory = () => StorageFactory.Blobs.DirectoryFiles(Path.Combine(currentAssemblyPath, "Workflows"))); return services; } } }