| | | 1 | | using Elsa.Workflows; |
| | | 2 | | using Microsoft.Extensions.DependencyInjection; |
| | | 3 | | |
| | | 4 | | // ReSharper disable once CheckNamespace |
| | | 5 | | namespace Elsa.Extensions; |
| | | 6 | | |
| | | 7 | | /// <summary> |
| | | 8 | | /// Extension methods for <see cref="IDictionary{TKey,TValue}"/>. |
| | | 9 | | /// </summary> |
| | | 10 | | public static class WorkflowDictionaryExtensions |
| | | 11 | | { |
| | | 12 | | /// <summary> |
| | | 13 | | /// Register a workflow factory that creates an instance of the specified workflow type. |
| | | 14 | | /// </summary> |
| | | 15 | | public static void Add<TWorkflow>(this IDictionary<string, Func<IServiceProvider, ValueTask<IWorkflow>>> dictionary) |
| | | 16 | | { |
| | | 17 | | // FullName should never be null here, as we filter out generic types |
| | 9 | 18 | | dictionary.Add(typeof(TWorkflow).FullName!, sp => |
| | 9 | 19 | | { |
| | 24 | 20 | | var workflow = ActivatorUtilities.GetServiceOrCreateInstance<TWorkflow>(sp); |
| | 24 | 21 | | return new ValueTask<IWorkflow>(workflow); |
| | 9 | 22 | | }); |
| | 9 | 23 | | } |
| | | 24 | | |
| | | 25 | | /// <summary> |
| | | 26 | | /// Register a workflow factory that creates an instance of the specified workflow type. |
| | | 27 | | /// </summary> |
| | | 28 | | public static void Add(this IDictionary<string, Func<IServiceProvider, ValueTask<IWorkflow>>> dictionary, Type workf |
| | | 29 | | { |
| | | 30 | | // FullName should never be null here, as we filter out generic types |
| | 49 | 31 | | dictionary.Add(workflowType.FullName!, sp => |
| | 49 | 32 | | { |
| | 392 | 33 | | var workflow = (IWorkflow)ActivatorUtilities.GetServiceOrCreateInstance(sp, workflowType); |
| | 392 | 34 | | return new ValueTask<IWorkflow>(workflow); |
| | 49 | 35 | | }); |
| | 49 | 36 | | } |
| | | 37 | | } |