| | | 1 | | using System.Reflection; |
| | | 2 | | using Elsa.Features.Services; |
| | | 3 | | using Elsa.Workflows; |
| | | 4 | | using Elsa.Workflows.Runtime.Features; |
| | | 5 | | |
| | | 6 | | // ReSharper disable once CheckNamespace |
| | | 7 | | namespace Elsa.Extensions; |
| | | 8 | | |
| | | 9 | | /// <summary> |
| | | 10 | | /// Adds extensions to setup the <see cref="WorkflowRuntimeFeature"/> feature. |
| | | 11 | | /// </summary> |
| | | 12 | | public static class ModuleExtensions |
| | | 13 | | { |
| | | 14 | | /// <summary> |
| | | 15 | | /// Enables the <see cref="WorkflowRuntimeFeature"/> feature. |
| | | 16 | | /// </summary> |
| | | 17 | | public static IModule UseWorkflowRuntime(this IModule module, Action<WorkflowRuntimeFeature>? configure = default) |
| | | 18 | | { |
| | 7 | 19 | | module.Configure(configure); |
| | 7 | 20 | | return module; |
| | | 21 | | } |
| | | 22 | | |
| | | 23 | | /// <summary> |
| | | 24 | | /// Register the specified workflow type. |
| | | 25 | | /// </summary> |
| | | 26 | | public static IModule AddWorkflow<T>(this IModule module) where T : IWorkflow |
| | | 27 | | { |
| | 9 | 28 | | module.Configure<WorkflowRuntimeFeature>().AddWorkflow<T>(); |
| | 9 | 29 | | return module; |
| | | 30 | | } |
| | | 31 | | |
| | | 32 | | /// <summary> |
| | | 33 | | /// Register all workflows contained in the assembly containing the specified marker type. |
| | | 34 | | /// </summary> |
| | 2 | 35 | | public static IModule AddWorkflowsFrom<TMarker>(this IModule module) => module.AddWorkflowsFrom(typeof(TMarker).Asse |
| | | 36 | | |
| | | 37 | | /// <summary> |
| | | 38 | | /// Register all workflows in the specified assembly. |
| | | 39 | | /// </summary> |
| | | 40 | | public static IModule AddWorkflowsFrom(this IModule module, Assembly assembly) |
| | | 41 | | { |
| | 2 | 42 | | module.Configure<WorkflowRuntimeFeature>().AddWorkflowsFrom(assembly); |
| | 2 | 43 | | return module; |
| | | 44 | | } |
| | | 45 | | |
| | | 46 | | /// <summary> |
| | | 47 | | /// Configures the default workflow runtime. |
| | | 48 | | /// </summary> |
| | | 49 | | /// <param name="feature">The workflow runtime feature.</param> |
| | | 50 | | /// <param name="configure">A callback that configures the default workflow runtime.</param> |
| | | 51 | | /// <returns>The workflow runtime feature.</returns> |
| | | 52 | | public static WorkflowRuntimeFeature UseDefaultRuntime(this WorkflowRuntimeFeature feature, Action<DefaultWorkflowRu |
| | | 53 | | { |
| | 0 | 54 | | feature.Module.Configure(configure); |
| | 0 | 55 | | return feature; |
| | | 56 | | } |
| | | 57 | | |
| | | 58 | | /// <summary> |
| | | 59 | | /// Adds caching stores feature to the workflow runtime feature. |
| | | 60 | | /// </summary> |
| | | 61 | | public static WorkflowRuntimeFeature UseCache(this WorkflowRuntimeFeature feature, Action<CachingWorkflowRuntimeFeat |
| | | 62 | | { |
| | 2 | 63 | | feature.Module.Configure(configure); |
| | 2 | 64 | | return feature; |
| | | 65 | | } |
| | | 66 | | } |