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

64 lines
3.2 KiB
C#
Raw Normal View History

2022-01-04 08:42:12 +00:00
using Elsa.Expressions;
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<WorkflowRuntimeOptions>();
return services
// Core.
.AddSingleton<IWorkflowRegistry, WorkflowRegistry>()
.AddSingleton<IStimulusInterpreter, StimulusInterpreter>()
.AddSingleton<IWorkflowInstructionExecutor, WorkflowInstructionExecutor>()
.AddSingleton<ITriggerIndexer, TriggerIndexer>()
2022-02-22 11:51:59 +00:00
.AddSingleton<IBookmarkManager, BookmarkManager>()
2022-01-04 08:42:12 +00:00
// Stimulus handlers.
.AddStimulusHandler<TriggerWorkflowsStimulusHandler>()
.AddStimulusHandler<ResumeWorkflowsStimulusHandler>()
// Instruction interpreters.
.AddInstructionInterpreter<TriggerWorkflowInstructionInterpreter>()
.AddInstructionInterpreter<ResumeWorkflowInstructionInterpreter>()
// Workflow providers.
.AddWorkflowProvider<ConfigurationWorkflowProvider>()
.AddWorkflowProvider<DatabaseWorkflowProvider>()
// Workflow engine.
2022-03-22 13:33:15 +00:00
.AddSingleton<IWorkflowService, WorkflowService>()
2022-01-04 08:42:12 +00:00
// Domain event handlers.
2022-01-04 08:42:12 +00:00
.AddNotificationHandlersFrom(typeof(ServiceCollectionExtensions))
// Hosted Services.
2022-02-22 11:51:59 +00:00
.AddHostedService<RegisterDescriptors>()
.AddHostedService<RegisterExpressionSyntaxDescriptors>();
2022-01-04 08:42:12 +00:00
;
}
private static IServiceCollection AddDefaultExpressionHandlers(this IServiceCollection services) =>
services
.AddExpressionHandler<LiteralExpressionHandler, LiteralExpression>()
.AddExpressionHandler<DelegateExpressionHandler, DelegateExpression>()
.AddExpressionHandler<VariableExpressionHandler, VariableExpression>()
.AddExpressionHandler<ElsaExpressionHandler, ElsaExpression>();
public static IServiceCollection AddWorkflowProvider<T>(this IServiceCollection services) where T : class, IWorkflowProvider => services.AddSingleton<IWorkflowProvider, T>();
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>();
public static IServiceCollection ConfigureWorkflowRuntime(this IServiceCollection services, Action<WorkflowRuntimeOptions> configure) => services.Configure(configure);
2022-02-22 11:51:59 +00:00
public static IServiceCollection IndexWorkflowTriggers(this IServiceCollection services) => services.AddHostedService<IndexWorkflowTriggers>();
2022-01-04 08:42:12 +00:00
}