| | | 1 | | using CShells.FastEndpoints.Features; |
| | | 2 | | using CShells.Features; |
| | | 3 | | using Elsa.Expressions.Options; |
| | | 4 | | using Elsa.Extensions; |
| | | 5 | | using Elsa.Resilience.Endpoints.SimulateResponse; |
| | | 6 | | using Elsa.Resilience.Entities; |
| | | 7 | | using Elsa.Resilience.Modifiers; |
| | | 8 | | using Elsa.Resilience.Options; |
| | | 9 | | using Elsa.Resilience.Recorders; |
| | | 10 | | using Elsa.Resilience.Serialization; |
| | | 11 | | using Elsa.Resilience.StrategySources; |
| | | 12 | | using Elsa.Workflows; |
| | | 13 | | using Elsa.Workflows.Options; |
| | | 14 | | using Microsoft.Extensions.DependencyInjection; |
| | | 15 | | using Microsoft.Extensions.DependencyInjection.Extensions; |
| | | 16 | | using Elsa.Common.Serialization; |
| | | 17 | | |
| | | 18 | | namespace Elsa.Resilience.ShellFeatures; |
| | | 19 | | |
| | | 20 | | [ShellFeature( |
| | | 21 | | DisplayName = "Resilience", |
| | | 22 | | Description = "Provides workflow resilience strategies and retry attempt tracking")] |
| | | 23 | | public class ResilienceFeature : IFastEndpointsShellFeature |
| | | 24 | | { |
| | | 25 | | public void ConfigureServices(IServiceCollection services) |
| | | 26 | | { |
| | 0 | 27 | | services.Configure<ExpressionOptions>(options => |
| | 0 | 28 | | { |
| | 0 | 29 | | options.AddTypeAlias<List<RetryAttemptRecord>>("RetryAttemptRecordList"); |
| | 0 | 30 | | }); |
| | | 31 | | |
| | 0 | 32 | | services.Configure<SerializationTypeOptions>(options => |
| | 0 | 33 | | { |
| | 0 | 34 | | options.RegisterTypeAlias(typeof(List<RetryAttemptRecord>), "RetryAttemptRecordList"); |
| | 0 | 35 | | }); |
| | | 36 | | |
| | 0 | 37 | | services.AddOptions<ResilienceOptions>(); |
| | 0 | 38 | | services.AddOptions<SimulateResponseOptions>(); |
| | 0 | 39 | | services.TryAddSingleton(TimeProvider.System); |
| | | 40 | | |
| | 0 | 41 | | services |
| | 0 | 42 | | .AddSingleton<ResilienceStrategySerializer>() |
| | 0 | 43 | | .AddSingleton<SimulateResponseSessionStore>() |
| | 0 | 44 | | .AddSingleton<IActivityDescriptorModifier, ResilientActivityDescriptorModifier>() |
| | 0 | 45 | | .AddScoped<IResilienceStrategyCatalog, ResilienceStrategyCatalog>() |
| | 0 | 46 | | .AddScoped<IResilienceStrategyConfigEvaluator, ResilienceStrategyConfigEvaluator>() |
| | 0 | 47 | | .AddScoped<IResilientActivityInvoker, ResilientActivityInvoker>() |
| | 0 | 48 | | .AddScoped<IResilienceStrategySource, ConfigurationResilienceStrategySource>() |
| | 0 | 49 | | .AddSingleton(VoidRetryAttemptRecorder.Instance) |
| | 0 | 50 | | .AddSingleton(VoidRetryAttemptReader.Instance) |
| | 0 | 51 | | .AddScoped<IRetryAttemptRecorder, ActivityExecutionContextRetryAttemptRecorder>() |
| | 0 | 52 | | .AddScoped<IRetryAttemptReader, ActivityExecutionContextRetryAttemptReader>() |
| | 0 | 53 | | .AddScoped<ActivityExecutionContextRetryAttemptReader>() |
| | 0 | 54 | | .AddHandlersFrom<ResilienceFeature>(); |
| | | 55 | | |
| | | 56 | | // Register transient exception detection infrastructure |
| | 0 | 57 | | services |
| | 0 | 58 | | .AddSingleton<ITransientExceptionStrategy, DefaultTransientExceptionStrategy>() |
| | 0 | 59 | | .AddSingleton<ITransientExceptionDetector, TransientExceptionDetector>(); |
| | 0 | 60 | | } |
| | | 61 | | } |