using System.Threading.Channels; using Elsa.Options; using Elsa.Runtime.Options; using Elsa.Runtime.Services; using Microsoft.Extensions.DependencyInjection; namespace Elsa.Runtime.Extensions; public static class ServiceCollectionExtensions { public static ElsaOptionsConfigurator ConfigureElsaRuntime(this ElsaOptionsConfigurator configurator, Action? configure = default) { configurator.Configure(configure); return configurator; } public static IServiceCollection CreateChannel(this IServiceCollection services) => services .AddSingleton(CreateChannel()) .AddSingleton(CreateChannelReader) .AddSingleton(CreateChannelWriter); private static Channel CreateChannel() => Channel.CreateUnbounded(new UnboundedChannelOptions()); private static ChannelReader CreateChannelReader(IServiceProvider serviceProvider) => serviceProvider.GetRequiredService>().Reader; private static ChannelWriter CreateChannelWriter(IServiceProvider serviceProvider) => serviceProvider.GetRequiredService>().Writer; public static IServiceCollection AddWorkflowDefinitionProvider(this IServiceCollection services) where T : class, IWorkflowDefinitionProvider => 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); }