< Summary

Information
Class: Elsa.Resilience.Features.ResilienceFeature
Assembly: Elsa.Resilience
File(s): /home/runner/work/elsa-core/elsa-core/src/modules/Elsa.Resilience/Features/ResilienceFeature.cs
Line coverage
78%
Covered lines: 30
Uncovered lines: 8
Coverable lines: 38
Total lines: 88
Line coverage: 78.9%
Branch coverage
0%
Covered branches: 0
Total branches: 4
Branch coverage: 0%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

File(s)

/home/runner/work/elsa-core/elsa-core/src/modules/Elsa.Resilience/Features/ResilienceFeature.cs

#LineLine coverage
 1using Elsa.Expressions.Options;
 2using Elsa.Extensions;
 3using Elsa.Features.Abstractions;
 4using Elsa.Features.Services;
 5using Elsa.Resilience.Entities;
 6using Elsa.Resilience.Modifiers;
 7using Elsa.Resilience.Options;
 8using Elsa.Resilience.Recorders;
 9using Elsa.Resilience.Serialization;
 10using Elsa.Resilience.StrategySources;
 11using Elsa.Workflows;
 12using Microsoft.Extensions.DependencyInjection;
 13
 14namespace Elsa.Resilience.Features;
 15
 216public class ResilienceFeature(IModule module) : FeatureBase(module)
 17{
 218    private Func<IServiceProvider, IRetryAttemptRecorder> _retryAttemptRecorder = sp => sp.GetRequiredService<ActivityEx
 319    private Func<IServiceProvider, IRetryAttemptReader> _retryAttemptReader = sp => sp.GetRequiredService<ActivityExecut
 20
 21    public ResilienceFeature AddResilienceStrategyType<T>() where T : IResilienceStrategy
 22    {
 223        return AddResilienceStrategyType(typeof(T));
 24    }
 25
 26    public ResilienceFeature AddResilienceStrategyType(Type strategyType)
 27    {
 328        Services.Configure<ResilienceOptions>(options => options.StrategyTypes.Add(strategyType));
 229        return this;
 30    }
 31
 32    public ResilienceFeature WithActivityExecutionContextRetryAttemptRecorder()
 33    {
 034        return WithRetryAttemptRecorder<ActivityExecutionContextRetryAttemptRecorder>()
 035            .WithRetryAttemptReader<ActivityExecutionContextRetryAttemptReader>();
 36    }
 37
 38    public ResilienceFeature WithVoidRetryAttemptRecorder()
 39    {
 040        return WithRetryAttemptRecorder<VoidRetryAttemptRecorder>()
 041            .WithRetryAttemptReader<VoidRetryAttemptReader>();
 42    }
 43
 044    public ResilienceFeature WithRetryAttemptRecorder<T>() => WithRetryAttemptRecorder(sp => (IRetryAttemptRecorder)Acti
 045    public ResilienceFeature WithRetryAttemptReader<T>() => WithRetryAttemptReader(sp => (IRetryAttemptReader)ActivatorU
 46
 47    public ResilienceFeature WithRetryAttemptRecorder(Func<IServiceProvider, IRetryAttemptRecorder> recorder)
 48    {
 149        _retryAttemptRecorder = recorder;
 150        return this;
 51    }
 52
 53    public ResilienceFeature WithRetryAttemptReader(Func<IServiceProvider, IRetryAttemptReader> reader)
 54    {
 055        _retryAttemptReader = reader;
 056        return this;
 57    }
 58
 59    public override void Configure()
 60    {
 261        Module.AddFastEndpointsAssembly<ResilienceFeature>();
 62
 263        Services.Configure<ExpressionOptions>(options =>
 264        {
 265            options.AddTypeAlias<List<RetryAttemptRecord>>("RetryAttemptRecordList");
 466        });
 267    }
 68
 69    public override void Apply()
 70    {
 271        Services.AddOptions<ResilienceOptions>();
 72
 273        Services
 274            .AddSingleton<ResilienceStrategySerializer>()
 275            .AddSingleton<IActivityDescriptorModifier, ResilientActivityDescriptorModifier>()
 276            .AddScoped<IResilienceStrategyCatalog, ResilienceStrategyCatalog>()
 277            .AddScoped<IResilienceStrategyConfigEvaluator, ResilienceStrategyConfigEvaluator>()
 278            .AddScoped<IResilientActivityInvoker, ResilientActivityInvoker>()
 279            .AddScoped<IResilienceStrategySource, ConfigurationResilienceStrategySource>()
 280            .AddSingleton(VoidRetryAttemptRecorder.Instance)
 281            .AddSingleton(VoidRetryAttemptReader.Instance)
 282            .AddScoped<ActivityExecutionContextRetryAttemptRecorder>()
 283            .AddScoped<ActivityExecutionContextRetryAttemptReader>()
 284            .AddScoped(_retryAttemptRecorder)
 285            .AddScoped(_retryAttemptReader)
 286            .AddHandlersFrom<ResilienceFeature>();
 287    }
 88}