2022-04-10 12:35:53 +00:00
|
|
|
using System.Threading.Channels;
|
2022-05-03 09:44:44 +00:00
|
|
|
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) =>
|
2022-04-10 12:35:53 +00:00
|
|
|
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;
|
|
|
|
|
|
2022-04-30 09:10:08 +00:00
|
|
|
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
|
|
|
}
|