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