< Summary

Information
Class: Elsa.Workflows.DefaultIncidentStrategyResolver
Assembly: Elsa.Workflows.Core
File(s): /home/runner/work/elsa-core/elsa-core/src/modules/Elsa.Workflows.Core/Services/DefaultIncidentStrategyResolver.cs
Line coverage
100%
Covered lines: 11
Uncovered lines: 0
Coverable lines: 11
Total lines: 44
Line coverage: 100%
Branch coverage
100%
Covered branches: 4
Total branches: 4
Branch coverage: 100%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.ctor(...)100%11100%
ResolveStrategyAsync(...)100%11100%
ResolveStrategyType(...)100%44100%

File(s)

/home/runner/work/elsa-core/elsa-core/src/modules/Elsa.Workflows.Core/Services/DefaultIncidentStrategyResolver.cs

#LineLine coverage
 1using Elsa.Workflows.IncidentStrategies;
 2using Elsa.Workflows.Options;
 3using Microsoft.Extensions.DependencyInjection;
 4using Microsoft.Extensions.Options;
 5
 6namespace Elsa.Workflows;
 7
 8/// <inheritdoc />
 9public class DefaultIncidentStrategyResolver : IIncidentStrategyResolver
 10{
 11    private readonly IOptions<IncidentOptions> _options;
 12    private readonly IServiceProvider _serviceProvider;
 13
 14    /// <summary>
 15    /// Initializes a new instance of the <see cref="DefaultIncidentStrategyResolver"/> class.
 16    /// </summary>
 42117    public DefaultIncidentStrategyResolver(IOptions<IncidentOptions> options, IServiceProvider serviceProvider)
 18    {
 42119        _options = options;
 42120        _serviceProvider = serviceProvider;
 42121    }
 22
 23    /// <inheritdoc />
 24    public ValueTask<IIncidentStrategy> ResolveStrategyAsync(ActivityExecutionContext context, CancellationToken cancell
 25    {
 1326        var strategyType = ResolveStrategyType(context);
 1327        var strategy = (IIncidentStrategy)ActivatorUtilities.GetServiceOrCreateInstance(_serviceProvider, strategyType);
 28
 1329        return new(strategy);
 30    }
 31
 32    private Type ResolveStrategyType(ActivityExecutionContext context)
 33    {
 34        // First check if the workflow is configured with an incident strategy.
 35        // If no strategy was configured there, use the application-level configured strategy.
 36
 1337        var strategyType = context.WorkflowExecutionContext.Workflow.Options.IncidentStrategyType;
 38
 1339        if(strategyType == null)
 840            strategyType = _options.Value.DefaultIncidentStrategy;
 41
 1342        return strategyType ?? typeof(FaultStrategy);
 43    }
 44}