| | | 1 | | using Elsa.Common; |
| | | 2 | | using Elsa.Common.Features; |
| | | 3 | | using Elsa.Common.Serialization; |
| | | 4 | | using Elsa.Expressions.Features; |
| | | 5 | | using Elsa.Extensions; |
| | | 6 | | using Elsa.Features.Abstractions; |
| | | 7 | | using Elsa.Features.Attributes; |
| | | 8 | | using Elsa.Features.Services; |
| | | 9 | | using Elsa.Workflows.ActivationValidators; |
| | | 10 | | using Elsa.Workflows.Builders; |
| | | 11 | | using Elsa.Workflows.CommitStates; |
| | | 12 | | using Elsa.Workflows.IncidentStrategies; |
| | | 13 | | using Elsa.Workflows.LogPersistence; |
| | | 14 | | using Elsa.Workflows.LogPersistence.Strategies; |
| | | 15 | | using Elsa.Workflows.Middleware.Activities; |
| | | 16 | | using Elsa.Workflows.Middleware.Workflows; |
| | | 17 | | using Elsa.Workflows.Pipelines.ActivityExecution; |
| | | 18 | | using Elsa.Workflows.Pipelines.WorkflowExecution; |
| | | 19 | | using Elsa.Workflows.PortResolvers; |
| | | 20 | | using Elsa.Workflows.Serialization.Configurators; |
| | | 21 | | using Elsa.Workflows.Serialization.Helpers; |
| | | 22 | | using Elsa.Workflows.Serialization.Serializers; |
| | | 23 | | using Elsa.Workflows.Services; |
| | | 24 | | using Elsa.Workflows.UIHints.CheckList; |
| | | 25 | | using Elsa.Workflows.UIHints.Dictionary; |
| | | 26 | | using Elsa.Workflows.UIHints.Dropdown; |
| | | 27 | | using Elsa.Workflows.UIHints.JsonEditor; |
| | | 28 | | using Elsa.Workflows.UIHints.RadioList; |
| | | 29 | | using Microsoft.Extensions.DependencyInjection; |
| | | 30 | | |
| | | 31 | | namespace 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))] |
| | | 42 | | public class WorkflowsFeature : FeatureBase |
| | | 43 | | { |
| | | 44 | | /// <inheritdoc /> |
| | 114 | 45 | | public WorkflowsFeature(IModule module) : base(module) |
| | | 46 | | { |
| | 114 | 47 | | } |
| | | 48 | | |
| | | 49 | | /// <summary> |
| | | 50 | | /// A factory that instantiates a concrete <see cref="IStandardInStreamProvider"/>. |
| | | 51 | | /// </summary> |
| | 228 | 52 | | public Func<IServiceProvider, IStandardInStreamProvider> StandardInStreamProvider { get; set; } = _ => new StandardI |
| | | 53 | | |
| | | 54 | | /// <summary> |
| | | 55 | | /// A factory that instantiates a concrete <see cref="IStandardOutStreamProvider"/>. |
| | | 56 | | /// </summary> |
| | 704 | 57 | | public Func<IServiceProvider, IStandardOutStreamProvider> StandardOutStreamProvider { get; set; } = _ => new Standar |
| | | 58 | | |
| | | 59 | | /// <summary> |
| | | 60 | | /// A factory that instantiates a concrete <see cref="IIdentityGenerator"/>. |
| | | 61 | | /// </summary> |
| | 342 | 62 | | public Func<IServiceProvider, IIdentityGenerator> IdentityGenerator { get; set; } = sp => new RandomLongIdentityGene |
| | | 63 | | |
| | | 64 | | /// <summary> |
| | | 65 | | /// A handler for committing workflow execution state. |
| | | 66 | | /// </summary> |
| | 342 | 67 | | 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> |
| | 342 | 72 | | public Func<IServiceProvider, ILoggerStateGenerator<WorkflowExecutionContext>> WorkflowLoggerStateGenerator { get; s |
| | | 73 | | |
| | | 74 | | /// <summary> |
| | | 75 | | /// A factory that instantiates a concrete <see cref="ILoggerStateGenerator{ActivityExecutionContext}"/>. |
| | | 76 | | /// </summary> |
| | 342 | 77 | | public Func<IServiceProvider, ILoggerStateGenerator<ActivityExecutionContext>> ActivityLoggerStateGenerator { get; s |
| | | 78 | | |
| | | 79 | | /// <summary> |
| | | 80 | | /// A delegate to configure the <see cref="IWorkflowExecutionPipeline"/>. |
| | | 81 | | /// </summary> |
| | 649 | 82 | | public Action<IWorkflowExecutionPipelineBuilder> WorkflowExecutionPipeline { get; set; } = builder => builder |
| | 114 | 83 | | .UseExceptionHandling() |
| | 114 | 84 | | .UseDefaultActivityScheduler(); |
| | | 85 | | |
| | | 86 | | /// <summary> |
| | | 87 | | /// A delegate to configure the <see cref="IActivityExecutionPipeline"/>. |
| | | 88 | | /// </summary> |
| | 649 | 89 | | 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 | | { |
| | 0 | 96 | | StandardInStreamProvider = provider; |
| | 0 | 97 | | 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 | | { |
| | 225 | 105 | | StandardOutStreamProvider = provider; |
| | 225 | 106 | | 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 | | { |
| | 0 | 114 | | IdentityGenerator = generator; |
| | 0 | 115 | | 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 | | { |
| | 0 | 123 | | WorkflowLoggerStateGenerator = generator; |
| | 0 | 124 | | 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 | | { |
| | 0 | 132 | | ActivityLoggerStateGenerator = generator; |
| | 0 | 133 | | 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 | | { |
| | 114 | 141 | | WorkflowExecutionPipeline = setup; |
| | 114 | 142 | | 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 | | { |
| | 114 | 150 | | ActivityExecutionPipeline = setup; |
| | 114 | 151 | | return this; |
| | | 152 | | } |
| | | 153 | | |
| | | 154 | | /// <inheritdoc /> |
| | | 155 | | public override void Apply() |
| | | 156 | | { |
| | 114 | 157 | | AddElsaCore(Services); |
| | 114 | 158 | | } |
| | | 159 | | |
| | | 160 | | private void AddElsaCore(IServiceCollection services) |
| | | 161 | | { |
| | 114 | 162 | | services |
| | 114 | 163 | | |
| | 114 | 164 | | // Core. |
| | 114 | 165 | | .AddScoped<IActivityInvoker, ActivityInvoker>() |
| | 114 | 166 | | .AddScoped<IWorkflowRunner, WorkflowRunner>() |
| | 114 | 167 | | .AddScoped<IActivityTestRunner, ActivityTestRunner>() |
| | 114 | 168 | | .AddScoped<IActivityVisitor, ActivityVisitor>() |
| | 114 | 169 | | .AddScoped<IIdentityGraphService, IdentityGraphService>() |
| | 114 | 170 | | .AddScoped<IWorkflowGraphBuilder, WorkflowGraphBuilder>() |
| | 114 | 171 | | .AddScoped<IWorkflowStateExtractor, WorkflowStateExtractor>() |
| | 114 | 172 | | .AddScoped<IActivitySchedulerFactory, ActivitySchedulerFactory>() |
| | 114 | 173 | | .AddSingleton<IWorkflowExecutionContextSchedulerStrategy, WorkflowExecutionContextSchedulerStrategy>() |
| | 114 | 174 | | .AddSingleton<IActivityExecutionContextSchedulerStrategy, ActivityExecutionContextSchedulerStrategy>() |
| | 114 | 175 | | .AddScoped(CommitStateHandler) |
| | 114 | 176 | | .AddSingleton<IHasher, Hasher>() |
| | 114 | 177 | | .AddSingleton<IStimulusHasher, StimulusHasher>() |
| | 114 | 178 | | .AddSingleton(IdentityGenerator) |
| | 0 | 179 | | .AddSingleton<IBookmarkPayloadSerializer>(sp => ActivatorUtilities.CreateInstance<BookmarkPayloadSerializer> |
| | 114 | 180 | | .AddSingleton<IActivityDescriber, ActivityDescriber>() |
| | 114 | 181 | | .AddSingleton<IActivityRegistry, ActivityRegistry>() |
| | 114 | 182 | | .AddScoped<IActivityRegistryLookupService, ActivityRegistryLookupService>() |
| | 114 | 183 | | .AddSingleton<IPropertyDefaultValueResolver, PropertyDefaultValueResolver>() |
| | 114 | 184 | | .AddSingleton<IPropertyUIHandlerResolver, PropertyUIHandlerResolver>() |
| | 114 | 185 | | .AddTransient<WorkflowBuilder>() |
| | 1463 | 186 | | .AddScoped(typeof(Func<IWorkflowBuilder>), sp => () => sp.GetRequiredService<WorkflowBuilder>()) |
| | 114 | 187 | | .AddScoped<IWorkflowBuilderFactory, WorkflowBuilderFactory>() |
| | 114 | 188 | | .AddScoped<IVariablePersistenceManager, VariablePersistenceManager>() |
| | 114 | 189 | | .AddScoped<IIncidentStrategyResolver, DefaultIncidentStrategyResolver>() |
| | 114 | 190 | | .AddScoped<IActivityStateFilterManager, DefaultActivityStateFilterManager>() |
| | 114 | 191 | | .AddScoped<IWorkflowInstanceVariableReader, DefaultWorkflowInstanceVariableReader>() |
| | 114 | 192 | | .AddScoped<IWorkflowInstanceVariableWriter, DefaultWorkflowInstanceVariableWriter>() |
| | 114 | 193 | | .AddScoped<DefaultActivityInputEvaluator>() |
| | 114 | 194 | | |
| | 114 | 195 | | // Incident Strategies. |
| | 114 | 196 | | .AddTransient<IIncidentStrategy, FaultStrategy>() |
| | 114 | 197 | | .AddTransient<IIncidentStrategy, ContinueWithIncidentsStrategy>() |
| | 114 | 198 | | |
| | 114 | 199 | | // Pipelines. |
| | 421 | 200 | | .AddScoped<IActivityExecutionPipeline>(sp => new ActivityExecutionPipeline(sp, ActivityExecutionPipeline)) |
| | 421 | 201 | | .AddScoped<IWorkflowExecutionPipeline>(sp => new WorkflowExecutionPipeline(sp, WorkflowExecutionPipeline)) |
| | 114 | 202 | | |
| | 114 | 203 | | // Built-in activity services. |
| | 114 | 204 | | .AddScoped<IActivityResolver, PropertyBasedActivityResolver>() |
| | 114 | 205 | | .AddScoped<IActivityResolver, SwitchActivityResolver>() |
| | 114 | 206 | | .AddSerializationOptionsConfigurator<AdditionalConvertersConfigurator>() |
| | 114 | 207 | | .AddSerializationOptionsConfigurator<CustomConstructorConfigurator>() |
| | 114 | 208 | | |
| | 114 | 209 | | // Domain event handlers. |
| | 114 | 210 | | .AddHandlersFrom<WorkflowsFeature>() |
| | 114 | 211 | | |
| | 114 | 212 | | // Stream providers. |
| | 114 | 213 | | .AddScoped(StandardInStreamProvider) |
| | 114 | 214 | | .AddScoped(StandardOutStreamProvider) |
| | 114 | 215 | | |
| | 114 | 216 | | // Storage drivers. |
| | 114 | 217 | | .AddScoped<IStorageDriverManager, StorageDriverManager>() |
| | 114 | 218 | | .AddStorageDriver<WorkflowStorageDriver>() |
| | 114 | 219 | | .AddStorageDriver<WorkflowInstanceStorageDriver>() |
| | 114 | 220 | | .AddStorageDriver<MemoryStorageDriver>() |
| | 114 | 221 | | |
| | 114 | 222 | | // Serialization. |
| | 114 | 223 | | .AddSingleton<IWorkflowStateSerializer, JsonWorkflowStateSerializer>() |
| | 114 | 224 | | .AddSingleton<IPayloadSerializer, JsonPayloadSerializer>() |
| | 114 | 225 | | .AddSingleton<IActivitySerializer, JsonActivitySerializer>() |
| | 114 | 226 | | .AddSingleton<IApiSerializer, ApiSerializer>() |
| | 114 | 227 | | .AddSingleton<ISafeSerializer, SafeSerializer>() |
| | 114 | 228 | | .AddSingleton<IJsonSerializer, StandardJsonSerializer>() |
| | 114 | 229 | | .AddSingleton<SyntheticPropertiesWriter>() |
| | 114 | 230 | | .AddSingleton<ActivityWriter>() |
| | 114 | 231 | | |
| | 114 | 232 | | // Instantiation strategies. |
| | 114 | 233 | | .AddScoped<IWorkflowActivationStrategy, AllowAlwaysStrategy>() |
| | 114 | 234 | | |
| | 114 | 235 | | // UI. |
| | 114 | 236 | | .AddScoped<IUIHintHandler, DropDownUIHintHandler>() |
| | 114 | 237 | | .AddScoped<IUIHintHandler, CheckListUIHintHandler>() |
| | 114 | 238 | | .AddScoped<IUIHintHandler, RadioListUIHintHandler>() |
| | 114 | 239 | | .AddScoped<IUIHintHandler, JsonEditorUIHintHandler>() |
| | 114 | 240 | | .AddScoped<IPropertyUIHandler, StaticCheckListOptionsProvider>() |
| | 114 | 241 | | .AddScoped<IPropertyUIHandler, StaticRadioListOptionsProvider>() |
| | 114 | 242 | | .AddScoped<IPropertyUIHandler, StaticDropDownOptionsProvider>() |
| | 114 | 243 | | .AddScoped<IPropertyUIHandler, JsonCodeOptionsProvider>() |
| | 114 | 244 | | .AddScoped<DictionaryValueEvaluator>() |
| | 114 | 245 | | .AddSingleton<IActivityDescriptorModifier, DictionaryUIHintInputModifier>() |
| | 114 | 246 | | |
| | 114 | 247 | | // Logger state generators. |
| | 114 | 248 | | .AddSingleton(WorkflowLoggerStateGenerator) |
| | 114 | 249 | | .AddSingleton(ActivityLoggerStateGenerator) |
| | 114 | 250 | | |
| | 114 | 251 | | // Log Persistence Strategies. |
| | 114 | 252 | | .AddScoped<ILogPersistenceStrategyService, DefaultLogPersistenceStrategyService>() |
| | 114 | 253 | | .AddScoped<ILogPersistenceStrategy, Include>() |
| | 114 | 254 | | .AddScoped<ILogPersistenceStrategy, Exclude>() |
| | 114 | 255 | | .AddScoped<ILogPersistenceStrategy, Inherit>() |
| | 114 | 256 | | .AddScoped<ILogPersistenceStrategy, Configuration>() |
| | 114 | 257 | | |
| | 114 | 258 | | // Logging |
| | 114 | 259 | | .AddLogging(); |
| | 114 | 260 | | } |
| | | 261 | | } |