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

71 lines
3.2 KiB
C#
Raw Normal View History

2022-01-04 08:42:12 +00:00
using Elsa.ActivityNodeResolvers;
using Elsa.Contracts;
using Elsa.Expressions;
using Elsa.Modules.Activities.Extensions;
2022-01-04 08:42:12 +00:00
using Elsa.Options;
using Elsa.Persistence.Extensions;
using Elsa.Pipelines.ActivityExecution;
using Elsa.Pipelines.WorkflowExecution;
using Elsa.Runtime.Contracts;
using Elsa.Runtime.Extensions;
using Elsa.Services;
using Microsoft.Extensions.DependencyInjection;
namespace Elsa.Extensions;
public static class ServiceCollectionExtensions
{
public static IServiceCollection AddElsa(this IServiceCollection services) => services
.AddElsaCore()
.AddElsaRuntime()
.AddDefaultExpressionHandlers();
public static IServiceCollection AddElsaCore(this IServiceCollection services)
{
services.AddOptions<WorkflowEngineOptions>();
return services
// Core.
.AddSingleton<IActivityInvoker, ActivityInvoker>()
2022-03-04 18:59:44 +00:00
.AddSingleton<IWorkflowRunner, WorkflowRunner>()
2022-01-04 08:42:12 +00:00
.AddSingleton<IActivityWalker, ActivityWalker>()
.AddSingleton<IIdentityGraphService, IdentityGraphService>()
.AddSingleton<IWorkflowStateSerializer, WorkflowStateSerializer>()
.AddSingleton<IActivitySchedulerFactory, ActivitySchedulerFactory>()
.AddSingleton<IActivityNodeResolver, OutboundActivityNodeResolver>()
.AddSingleton<IHasher, Hasher>()
.AddSingleton<IIdentityGenerator, IdentityGenerator>()
.AddSingleton<ISystemClock, SystemClock>()
2022-03-07 11:01:27 +00:00
.AddSingleton<IBookmarkDataSerializer, BookmarkDataSerializer>()
2022-01-04 08:42:12 +00:00
// Expressions.
.AddSingleton<IExpressionEvaluator, ExpressionEvaluator>()
.AddSingleton<IExpressionHandlerRegistry, ExpressionHandlerRegistry>()
// Pipelines.
.AddSingleton<IActivityExecutionPipeline, ActivityExecutionPipeline>()
.AddSingleton<IWorkflowExecutionPipeline, WorkflowExecutionPipeline>()
2022-03-22 13:33:15 +00:00
// Additional activity services.
.AddActivityServices()
2022-01-04 08:42:12 +00:00
// Persistence services.
.AddPersistenceServices()
// Logging
.AddLogging();
}
private static IServiceCollection AddDefaultExpressionHandlers(this IServiceCollection services) =>
services
.AddExpressionHandler<LiteralExpressionHandler, LiteralExpression>()
.AddExpressionHandler<DelegateExpressionHandler, DelegateExpression>()
.AddExpressionHandler<VariableExpressionHandler, VariableExpression>()
.AddExpressionHandler<JsonExpressionHandler, JsonExpression>()
.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>();
}