< 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>
 47217    public DefaultIncidentStrategyResolver(IOptions<IncidentOptions> options, IServiceProvider serviceProvider)
 18    {
 47219        _options = options;
 47220        _serviceProvider = serviceProvider;
 47221    }
 22
 23    /// <inheritdoc />
 24    public ValueTask<IIncidentStrategy> ResolveStrategyAsync(ActivityExecutionContext context, CancellationToken cancell
 25    {
 1426        var strategyType = ResolveStrategyType(context);
 1427        var strategy = (IIncidentStrategy)ActivatorUtilities.GetServiceOrCreateInstance(_serviceProvider, strategyType);
 28
 1429        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
 1437        var strategyType = context.WorkflowExecutionContext.Workflow.Options.IncidentStrategyType;
 38
 1439        if(strategyType == null)
 940            strategyType = _options.Value.DefaultIncidentStrategy;
 41
 1442        return strategyType ?? typeof(FaultStrategy);
 43    }
 44}