using Elsa.Expressions; using Elsa.Extensions; using Elsa.Mediator.Extensions; using Elsa.Runtime.Contracts; using Elsa.Runtime.HostedServices; using Elsa.Runtime.Interpreters; using Elsa.Runtime.Options; using Elsa.Runtime.Services; using Elsa.Runtime.Stimuli.Handlers; using Elsa.Runtime.WorkflowProviders; using Microsoft.Extensions.DependencyInjection; namespace Elsa.Runtime.Extensions; public static class ServiceCollectionExtensions { public static IServiceCollection AddElsaRuntime(this IServiceCollection services) { services.AddOptions(); return services // Core. .AddSingleton() .AddSingleton() .AddSingleton() .AddSingleton() // Stimulus handlers. .AddStimulusHandler() .AddStimulusHandler() // Instruction interpreters. .AddInstructionInterpreter() .AddInstructionInterpreter() // Workflow providers. .AddWorkflowProvider() .AddWorkflowProvider() // Workflow engine. .AddSingleton() // Domain event handlers .AddNotificationHandlersFrom(typeof(ServiceCollectionExtensions)) // Hosted Sercices .AddHostedService() .AddHostedService(); ; } private static IServiceCollection AddDefaultExpressionHandlers(this IServiceCollection services) => services .AddExpressionHandler() .AddExpressionHandler() .AddExpressionHandler() .AddExpressionHandler(); public static IServiceCollection AddWorkflowProvider(this IServiceCollection services) where T : class, IWorkflowProvider => services.AddSingleton(); public static IServiceCollection AddStimulusHandler(this IServiceCollection services) where T : class, IStimulusHandler => services.AddSingleton(); public static IServiceCollection AddInstructionInterpreter(this IServiceCollection services) where T : class, IWorkflowInstructionInterpreter => services.AddSingleton(); public static IServiceCollection ConfigureWorkflowRuntime(this IServiceCollection services, Action configure) => services.Configure(configure); public static IServiceCollection IndexWorkflowTriggers(this IServiceCollection services) => services.AddHostedService(); }