< Summary

Information
Class: Elsa.Workflows.Features.WorkflowsFeature
Assembly: Elsa.Workflows.Core
File(s): /home/runner/work/elsa-core/elsa-core/src/modules/Elsa.Workflows.Core/Features/WorkflowsFeature.cs
Line coverage
92%
Covered lines: 118
Uncovered lines: 9
Coverable lines: 127
Total lines: 261
Line coverage: 92.9%
Branch coverage
N/A
Covered branches: 0
Total branches: 0
Branch coverage: N/A
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

File(s)

/home/runner/work/elsa-core/elsa-core/src/modules/Elsa.Workflows.Core/Features/WorkflowsFeature.cs

#LineLine coverage
 1using Elsa.Common;
 2using Elsa.Common.Features;
 3using Elsa.Common.Serialization;
 4using Elsa.Expressions.Features;
 5using Elsa.Extensions;
 6using Elsa.Features.Abstractions;
 7using Elsa.Features.Attributes;
 8using Elsa.Features.Services;
 9using Elsa.Workflows.ActivationValidators;
 10using Elsa.Workflows.Builders;
 11using Elsa.Workflows.CommitStates;
 12using Elsa.Workflows.IncidentStrategies;
 13using Elsa.Workflows.LogPersistence;
 14using Elsa.Workflows.LogPersistence.Strategies;
 15using Elsa.Workflows.Middleware.Activities;
 16using Elsa.Workflows.Middleware.Workflows;
 17using Elsa.Workflows.Pipelines.ActivityExecution;
 18using Elsa.Workflows.Pipelines.WorkflowExecution;
 19using Elsa.Workflows.PortResolvers;
 20using Elsa.Workflows.Serialization.Configurators;
 21using Elsa.Workflows.Serialization.Helpers;
 22using Elsa.Workflows.Serialization.Serializers;
 23using Elsa.Workflows.Services;
 24using Elsa.Workflows.UIHints.CheckList;
 25using Elsa.Workflows.UIHints.Dictionary;
 26using Elsa.Workflows.UIHints.Dropdown;
 27using Elsa.Workflows.UIHints.JsonEditor;
 28using Elsa.Workflows.UIHints.RadioList;
 29using Microsoft.Extensions.DependencyInjection;
 30
 31namespace Elsa.Workflows.Features;
 32
 33/// <summary>
 34/// Adds workflow services to the system.
 35/// </summary>
 36[DependsOn(typeof(SystemClockFeature))]
 37[DependsOn(typeof(ExpressionsFeature))]
 38[DependsOn(typeof(MediatorFeature))]
 39[DependsOn(typeof(DefaultFormattersFeature))]
 40[DependsOn(typeof(MultitenancyFeature))]
 41[DependsOn(typeof(CommitStrategiesFeature))]
 42public class WorkflowsFeature : FeatureBase
 43{
 44    /// <inheritdoc />
 11445    public WorkflowsFeature(IModule module) : base(module)
 46    {
 11447    }
 48
 49    /// <summary>
 50    /// A factory that instantiates a concrete <see cref="IStandardInStreamProvider"/>.
 51    /// </summary>
 22852    public Func<IServiceProvider, IStandardInStreamProvider> StandardInStreamProvider { get; set; } = _ => new StandardI
 53
 54    /// <summary>
 55    /// A factory that instantiates a concrete <see cref="IStandardOutStreamProvider"/>.
 56    /// </summary>
 70457    public Func<IServiceProvider, IStandardOutStreamProvider> StandardOutStreamProvider { get; set; } = _ => new Standar
 58
 59    /// <summary>
 60    /// A factory that instantiates a concrete <see cref="IIdentityGenerator"/>.
 61    /// </summary>
 34262    public Func<IServiceProvider, IIdentityGenerator> IdentityGenerator { get; set; } = sp => new RandomLongIdentityGene
 63
 64    /// <summary>
 65    /// A handler for committing workflow execution state.
 66    /// </summary>
 34267    public Func<IServiceProvider, ICommitStateHandler> CommitStateHandler { get; set; } = sp => new NoopCommitStateHandl
 68
 69    /// <summary>
 70    /// A factory that instantiates a concrete <see cref="ILoggerStateGenerator{WorkflowExecutionContext}"/>.
 71    /// </summary>
 34272    public Func<IServiceProvider, ILoggerStateGenerator<WorkflowExecutionContext>> WorkflowLoggerStateGenerator { get; s
 73
 74    /// <summary>
 75    /// A factory that instantiates a concrete <see cref="ILoggerStateGenerator{ActivityExecutionContext}"/>.
 76    /// </summary>
 34277    public Func<IServiceProvider, ILoggerStateGenerator<ActivityExecutionContext>> ActivityLoggerStateGenerator { get; s
 78
 79    /// <summary>
 80    /// A delegate to configure the <see cref="IWorkflowExecutionPipeline"/>.
 81    /// </summary>
 64982    public Action<IWorkflowExecutionPipelineBuilder> WorkflowExecutionPipeline { get; set; } = builder => builder
 11483        .UseExceptionHandling()
 11484        .UseDefaultActivityScheduler();
 85
 86    /// <summary>
 87    /// A delegate to configure the <see cref="IActivityExecutionPipeline"/>.
 88    /// </summary>
 64989    public Action<IActivityExecutionPipelineBuilder> ActivityExecutionPipeline { get; set; } = builder => builder.UseDef
 90
 91    /// <summary>
 92    /// Fluent method to set <see cref="StandardInStreamProvider"/>.
 93    /// </summary>
 94    public WorkflowsFeature WithStandardInStreamProvider(Func<IServiceProvider, IStandardInStreamProvider> provider)
 95    {
 096        StandardInStreamProvider = provider;
 097        return this;
 98    }
 99
 100    /// <summary>
 101    /// Fluent method to set <see cref="StandardOutStreamProvider"/>.
 102    /// </summary>
 103    public WorkflowsFeature WithStandardOutStreamProvider(Func<IServiceProvider, IStandardOutStreamProvider> provider)
 104    {
 225105        StandardOutStreamProvider = provider;
 225106        return this;
 107    }
 108
 109    /// <summary>
 110    /// Fluent method to set <see cref="IdentityGenerator"/>.
 111    /// </summary>
 112    public WorkflowsFeature WithIdentityGenerator(Func<IServiceProvider, IIdentityGenerator> generator)
 113    {
 0114        IdentityGenerator = generator;
 0115        return this;
 116    }
 117
 118    /// <summary>
 119    /// Fluent method to set <see cref="ILoggerStateGenerator{WorkflowExecutionContext}"/>.
 120    /// </summary>
 121    public WorkflowsFeature WithWorkflowLoggerStateGenerator(Func<IServiceProvider, ILoggerStateGenerator<WorkflowExecut
 122    {
 0123        WorkflowLoggerStateGenerator = generator;
 0124        return this;
 125    }
 126
 127    /// <summary>
 128    /// Fluent method to set <see cref="ILoggerStateGenerator{ActivityExecutionContext}"/>.
 129    /// </summary>
 130    public WorkflowsFeature WithActivityLoggerStateGenerator(Func<IServiceProvider, ILoggerStateGenerator<ActivityExecut
 131    {
 0132        ActivityLoggerStateGenerator = generator;
 0133        return this;
 134    }
 135
 136    /// <summary>
 137    /// Fluent method to configure the <see cref="IWorkflowExecutionPipeline"/>.
 138    /// </summary>
 139    public WorkflowsFeature WithWorkflowExecutionPipeline(Action<IWorkflowExecutionPipelineBuilder> setup)
 140    {
 114141        WorkflowExecutionPipeline = setup;
 114142        return this;
 143    }
 144
 145    /// <summary>
 146    /// Fluent method to configure the <see cref="IActivityExecutionPipeline"/>.
 147    /// </summary>
 148    public WorkflowsFeature WithActivityExecutionPipeline(Action<IActivityExecutionPipelineBuilder> setup)
 149    {
 114150        ActivityExecutionPipeline = setup;
 114151        return this;
 152    }
 153
 154    /// <inheritdoc />
 155    public override void Apply()
 156    {
 114157        AddElsaCore(Services);
 114158    }
 159
 160    private void AddElsaCore(IServiceCollection services)
 161    {
 114162        services
 114163
 114164            // Core.
 114165            .AddScoped<IActivityInvoker, ActivityInvoker>()
 114166            .AddScoped<IWorkflowRunner, WorkflowRunner>()
 114167            .AddScoped<IActivityTestRunner, ActivityTestRunner>()
 114168            .AddScoped<IActivityVisitor, ActivityVisitor>()
 114169            .AddScoped<IIdentityGraphService, IdentityGraphService>()
 114170            .AddScoped<IWorkflowGraphBuilder, WorkflowGraphBuilder>()
 114171            .AddScoped<IWorkflowStateExtractor, WorkflowStateExtractor>()
 114172            .AddScoped<IActivitySchedulerFactory, ActivitySchedulerFactory>()
 114173            .AddSingleton<IWorkflowExecutionContextSchedulerStrategy, WorkflowExecutionContextSchedulerStrategy>()
 114174            .AddSingleton<IActivityExecutionContextSchedulerStrategy, ActivityExecutionContextSchedulerStrategy>()
 114175            .AddScoped(CommitStateHandler)
 114176            .AddSingleton<IHasher, Hasher>()
 114177            .AddSingleton<IStimulusHasher, StimulusHasher>()
 114178            .AddSingleton(IdentityGenerator)
 0179            .AddSingleton<IBookmarkPayloadSerializer>(sp => ActivatorUtilities.CreateInstance<BookmarkPayloadSerializer>
 114180            .AddSingleton<IActivityDescriber, ActivityDescriber>()
 114181            .AddSingleton<IActivityRegistry, ActivityRegistry>()
 114182            .AddScoped<IActivityRegistryLookupService, ActivityRegistryLookupService>()
 114183            .AddSingleton<IPropertyDefaultValueResolver, PropertyDefaultValueResolver>()
 114184            .AddSingleton<IPropertyUIHandlerResolver, PropertyUIHandlerResolver>()
 114185            .AddTransient<WorkflowBuilder>()
 1463186            .AddScoped(typeof(Func<IWorkflowBuilder>), sp => () => sp.GetRequiredService<WorkflowBuilder>())
 114187            .AddScoped<IWorkflowBuilderFactory, WorkflowBuilderFactory>()
 114188            .AddScoped<IVariablePersistenceManager, VariablePersistenceManager>()
 114189            .AddScoped<IIncidentStrategyResolver, DefaultIncidentStrategyResolver>()
 114190            .AddScoped<IActivityStateFilterManager, DefaultActivityStateFilterManager>()
 114191            .AddScoped<IWorkflowInstanceVariableReader, DefaultWorkflowInstanceVariableReader>()
 114192            .AddScoped<IWorkflowInstanceVariableWriter, DefaultWorkflowInstanceVariableWriter>()
 114193            .AddScoped<DefaultActivityInputEvaluator>()
 114194
 114195            // Incident Strategies.
 114196            .AddTransient<IIncidentStrategy, FaultStrategy>()
 114197            .AddTransient<IIncidentStrategy, ContinueWithIncidentsStrategy>()
 114198
 114199            // Pipelines.
 421200            .AddScoped<IActivityExecutionPipeline>(sp => new ActivityExecutionPipeline(sp, ActivityExecutionPipeline))
 421201            .AddScoped<IWorkflowExecutionPipeline>(sp => new WorkflowExecutionPipeline(sp, WorkflowExecutionPipeline))
 114202
 114203            // Built-in activity services.
 114204            .AddScoped<IActivityResolver, PropertyBasedActivityResolver>()
 114205            .AddScoped<IActivityResolver, SwitchActivityResolver>()
 114206            .AddSerializationOptionsConfigurator<AdditionalConvertersConfigurator>()
 114207            .AddSerializationOptionsConfigurator<CustomConstructorConfigurator>()
 114208
 114209            // Domain event handlers.
 114210            .AddHandlersFrom<WorkflowsFeature>()
 114211
 114212            // Stream providers.
 114213            .AddScoped(StandardInStreamProvider)
 114214            .AddScoped(StandardOutStreamProvider)
 114215
 114216            // Storage drivers.
 114217            .AddScoped<IStorageDriverManager, StorageDriverManager>()
 114218            .AddStorageDriver<WorkflowStorageDriver>()
 114219            .AddStorageDriver<WorkflowInstanceStorageDriver>()
 114220            .AddStorageDriver<MemoryStorageDriver>()
 114221
 114222            // Serialization.
 114223            .AddSingleton<IWorkflowStateSerializer, JsonWorkflowStateSerializer>()
 114224            .AddSingleton<IPayloadSerializer, JsonPayloadSerializer>()
 114225            .AddSingleton<IActivitySerializer, JsonActivitySerializer>()
 114226            .AddSingleton<IApiSerializer, ApiSerializer>()
 114227            .AddSingleton<ISafeSerializer, SafeSerializer>()
 114228            .AddSingleton<IJsonSerializer, StandardJsonSerializer>()
 114229            .AddSingleton<SyntheticPropertiesWriter>()
 114230            .AddSingleton<ActivityWriter>()
 114231
 114232            // Instantiation strategies.
 114233            .AddScoped<IWorkflowActivationStrategy, AllowAlwaysStrategy>()
 114234
 114235            // UI.
 114236            .AddScoped<IUIHintHandler, DropDownUIHintHandler>()
 114237            .AddScoped<IUIHintHandler, CheckListUIHintHandler>()
 114238            .AddScoped<IUIHintHandler, RadioListUIHintHandler>()
 114239            .AddScoped<IUIHintHandler, JsonEditorUIHintHandler>()
 114240            .AddScoped<IPropertyUIHandler, StaticCheckListOptionsProvider>()
 114241            .AddScoped<IPropertyUIHandler, StaticRadioListOptionsProvider>()
 114242            .AddScoped<IPropertyUIHandler, StaticDropDownOptionsProvider>()
 114243            .AddScoped<IPropertyUIHandler, JsonCodeOptionsProvider>()
 114244            .AddScoped<DictionaryValueEvaluator>()
 114245            .AddSingleton<IActivityDescriptorModifier, DictionaryUIHintInputModifier>()
 114246
 114247            // Logger state generators.
 114248            .AddSingleton(WorkflowLoggerStateGenerator)
 114249            .AddSingleton(ActivityLoggerStateGenerator)
 114250
 114251            // Log Persistence Strategies.
 114252            .AddScoped<ILogPersistenceStrategyService, DefaultLogPersistenceStrategyService>()
 114253            .AddScoped<ILogPersistenceStrategy, Include>()
 114254            .AddScoped<ILogPersistenceStrategy, Exclude>()
 114255            .AddScoped<ILogPersistenceStrategy, Inherit>()
 114256            .AddScoped<ILogPersistenceStrategy, Configuration>()
 114257
 114258            // Logging
 114259            .AddLogging();
 114260    }
 261}