< Summary

Information
Class: Elsa.Workflows.Management.Materializers.ClrWorkflowMaterializerContext
Assembly: Elsa.Workflows.Management
File(s): /home/runner/work/elsa-core/elsa-core/src/modules/Elsa.Workflows.Management/Materializers/ClrWorkflowMaterializer.cs
Line coverage
100%
Covered lines: 1
Uncovered lines: 0
Coverable lines: 1
Total lines: 51
Line coverage: 100%
Branch coverage
N/A
Covered branches: 0
Total branches: 0
Branch coverage: N/A
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
get_WorkflowBuilderType()100%11100%

File(s)

/home/runner/work/elsa-core/elsa-core/src/modules/Elsa.Workflows.Management/Materializers/ClrWorkflowMaterializer.cs

#LineLine coverage
 1using Elsa.Workflows.Activities;
 2using Elsa.Workflows.Management.Entities;
 3using Elsa.Workflows.Models;
 4using Microsoft.Extensions.DependencyInjection;
 5
 6namespace Elsa.Workflows.Management.Materializers;
 7
 8/// <summary>
 9/// A workflow materializer that deserializes workflows created in C# code.
 10/// </summary>
 11public class ClrWorkflowMaterializer(
 12    IPayloadSerializer payloadSerializer,
 13    IWorkflowBuilderFactory workflowBuilderFactory,
 14    IServiceProvider serviceProvider) : IWorkflowMaterializer
 15{
 16    /// <summary>
 17    /// The name of the materializer.
 18    /// </summary>
 19    public const string MaterializerName = "CLR";
 20
 21    /// <inheritdoc />
 22    public string Name => MaterializerName;
 23
 24    /// <inheritdoc />
 25    public async ValueTask<Workflow> MaterializeAsync(WorkflowDefinition definition, CancellationToken cancellationToken
 26    {
 27        var providerContext = payloadSerializer.Deserialize<ClrWorkflowMaterializerContext>(definition.MaterializerConte
 28        var workflowBuilderType = providerContext.WorkflowBuilderType == null! ? typeof(NotFoundWorkflowBuilder) : provi
 29        var workflowBuilder = (IWorkflow)ActivatorUtilities.GetServiceOrCreateInstance(serviceProvider, workflowBuilderT
 30        var workflowDefinitionBuilder = workflowBuilderFactory.CreateBuilder();
 31        var workflow = await workflowDefinitionBuilder.BuildWorkflowAsync(workflowBuilder, cancellationToken);
 32
 33        // Assign identities from the definition.
 34        workflow.Identity = new WorkflowIdentity(definition.DefinitionId, definition.Version, definition.Id, definition.
 35
 36        return workflow;
 37    }
 38}
 39
 40/// <summary>
 41/// Provides context for the CLR workflow materializer.
 42/// </summary>
 43/// <param name="WorkflowBuilderType">The type of the workflow builder.</param>
 224644public record ClrWorkflowMaterializerContext(Type WorkflowBuilderType);
 45
 46/// <summary>
 47/// A workflow builder that is used when the workflow builder type is not found.
 48/// </summary>
 49public class NotFoundWorkflowBuilder : WorkflowBase
 50{
 51}

Methods/Properties

get_WorkflowBuilderType()