| | | 1 | | using Elsa.Alterations.Core.Contracts; |
| | | 2 | | using Elsa.Alterations.Core.Entities; |
| | | 3 | | using Elsa.Alterations.Core.Extensions; |
| | | 4 | | using Elsa.Alterations.Core.Models; |
| | | 5 | | using Elsa.Alterations.Core.Stores; |
| | | 6 | | using Elsa.Alterations.Extensions; |
| | | 7 | | using Elsa.Alterations.Services; |
| | | 8 | | using Elsa.Alterations.Workflows; |
| | | 9 | | using Elsa.Extensions; |
| | | 10 | | using Elsa.Features.Abstractions; |
| | | 11 | | using Elsa.Features.Services; |
| | | 12 | | using Elsa.Workflows.Options; |
| | | 13 | | using Microsoft.Extensions.DependencyInjection; |
| | | 14 | | using Elsa.Common.Serialization; |
| | | 15 | | |
| | | 16 | | namespace Elsa.Alterations.Features; |
| | | 17 | | |
| | | 18 | | /// <summary> |
| | | 19 | | /// Adds the Elsa alterations services. |
| | | 20 | | /// </summary> |
| | | 21 | | public class AlterationsFeature : FeatureBase |
| | | 22 | | { |
| | | 23 | | /// <inheritdoc /> |
| | 6 | 24 | | public AlterationsFeature(IModule module) : base(module) |
| | | 25 | | { |
| | 6 | 26 | | } |
| | | 27 | | |
| | | 28 | | /// <summary> |
| | | 29 | | /// Gets or sets the factory for the alteration plan store. |
| | | 30 | | /// </summary> |
| | 16 | 31 | | public Func<IServiceProvider, IAlterationPlanStore> AlterationPlanStoreFactory { get; set; } = sp => sp.GetRequiredS |
| | | 32 | | |
| | | 33 | | /// <summary> |
| | | 34 | | /// Gets or sets the factory for the alteration job store. |
| | | 35 | | /// </summary> |
| | 16 | 36 | | public Func<IServiceProvider, IAlterationJobStore> AlterationJobStoreFactory { get; set; } = sp => sp.GetRequiredSer |
| | | 37 | | |
| | | 38 | | /// <summary> |
| | | 39 | | /// Gets or sets the factory for the alteration job dispatcher. |
| | | 40 | | /// </summary> |
| | 12 | 41 | | public Func<IServiceProvider, IAlterationJobDispatcher> AlterationJobDispatcherFactory { get; set; } = sp => sp.GetR |
| | | 42 | | |
| | | 43 | | /// <summary> |
| | | 44 | | /// Adds an alteration and its handler. |
| | | 45 | | /// </summary> |
| | | 46 | | /// <typeparam name="T">The type of alteration.</typeparam> |
| | | 47 | | /// <typeparam name="THandler">The type of alteration handler.</typeparam> |
| | | 48 | | public AlterationsFeature AddAlteration<T, THandler>() where T : class, IAlteration where THandler : class, IAlterat |
| | | 49 | | { |
| | 0 | 50 | | Services.AddAlteration<T, THandler>(); |
| | 0 | 51 | | return this; |
| | | 52 | | } |
| | | 53 | | |
| | | 54 | | /// <inheritdoc /> |
| | | 55 | | public override void Configure() |
| | | 56 | | { |
| | 6 | 57 | | Module.AddFastEndpointsAssembly<AlterationsFeature>(); |
| | 6 | 58 | | Module.AddWorkflow<ExecuteAlterationPlanWorkflow>(); |
| | 6 | 59 | | } |
| | | 60 | | |
| | | 61 | | /// <inheritdoc /> |
| | | 62 | | public override void Apply() |
| | | 63 | | { |
| | 6 | 64 | | Services.Configure<SerializationTypeOptions>(options => |
| | 6 | 65 | | { |
| | 4 | 66 | | options.RegisterTypeAlias(typeof(AlterationPlanParams), nameof(AlterationPlanParams)); |
| | 4 | 67 | | options.RegisterLegacySimpleAssemblyQualifiedName(typeof(AlterationPlanParams)); |
| | 10 | 68 | | }); |
| | | 69 | | |
| | 6 | 70 | | Services.AddScoped<IAlterationPlanManager, AlterationPlanManager>(); |
| | 6 | 71 | | Services.AddAlterations(); |
| | 6 | 72 | | Services.AddAlterationsCore(); |
| | 6 | 73 | | Services.AddScoped<BackgroundAlterationJobDispatcher>(); |
| | 6 | 74 | | Services.AddScoped<IAlterationPlanScheduler, DefaultAlterationPlanScheduler>(); |
| | 6 | 75 | | Services.AddScoped<IAlterationJobRunner, DefaultAlterationJobRunner>(); |
| | 6 | 76 | | Services.AddScoped<IAlterationRunner, DefaultAlterationRunner>(); |
| | | 77 | | |
| | 6 | 78 | | Services.AddMemoryStore<AlterationPlan, MemoryAlterationPlanStore>(); |
| | 6 | 79 | | Services.AddMemoryStore<AlterationJob, MemoryAlterationJobStore>(); |
| | | 80 | | |
| | 6 | 81 | | Services.AddScoped(AlterationPlanStoreFactory); |
| | 6 | 82 | | Services.AddScoped(AlterationJobStoreFactory); |
| | 6 | 83 | | Services.AddScoped(AlterationJobDispatcherFactory); |
| | 6 | 84 | | } |
| | | 85 | | } |