elsa-core/src/core/Elsa.Runtime/Extensions/ServiceCollectionExtensions.cs

31 lines
1.9 KiB
C#
Raw Normal View History

using System.Threading.Channels;
using Elsa.Options;
2022-01-04 08:42:12 +00:00
using Elsa.Runtime.Options;
using Elsa.Runtime.Services;
using Microsoft.Extensions.DependencyInjection;
namespace Elsa.Runtime.Extensions;
public static class ServiceCollectionExtensions
{
2022-05-03 14:17:20 +00:00
public static ElsaOptionsConfigurator ConfigureElsaRuntime(this ElsaOptionsConfigurator configurator, Action<ElsaRuntimeOptions>? configure = default)
2022-01-04 08:42:12 +00:00
{
2022-05-03 14:17:20 +00:00
configurator.Configure(configure);
return configurator;
2022-01-04 08:42:12 +00:00
}
2022-05-03 14:17:20 +00:00
public static IServiceCollection CreateChannel<T>(this IServiceCollection services) =>
services
.AddSingleton(CreateChannel<T>())
.AddSingleton(CreateChannelReader<T>)
.AddSingleton(CreateChannelWriter<T>);
private static Channel<T> CreateChannel<T>() => Channel.CreateUnbounded<T>(new UnboundedChannelOptions());
private static ChannelReader<T> CreateChannelReader<T>(IServiceProvider serviceProvider) => serviceProvider.GetRequiredService<Channel<T>>().Reader;
private static ChannelWriter<T> CreateChannelWriter<T>(IServiceProvider serviceProvider) => serviceProvider.GetRequiredService<Channel<T>>().Writer;
public static IServiceCollection AddWorkflowDefinitionProvider<T>(this IServiceCollection services) where T : class, IWorkflowDefinitionProvider => services.AddSingleton<IWorkflowDefinitionProvider, T>();
2022-01-04 08:42:12 +00:00
public static IServiceCollection AddStimulusHandler<T>(this IServiceCollection services) where T : class, IStimulusHandler => services.AddSingleton<IStimulusHandler, T>();
public static IServiceCollection AddInstructionInterpreter<T>(this IServiceCollection services) where T : class, IWorkflowInstructionInterpreter => services.AddSingleton<IWorkflowInstructionInterpreter, T>();
2022-05-03 14:17:20 +00:00
public static IServiceCollection ConfigureWorkflowRuntime(this IServiceCollection services, Action<ElsaRuntimeOptions> configure) => services.Configure(configure);
2022-01-04 08:42:12 +00:00
}