< Summary

Information
Class: Elsa.Expressions.JavaScript.Features.JavaScriptFeature
Assembly: Elsa.Expressions.JavaScript
File(s): /home/runner/work/elsa-core/elsa-core/src/modules/Elsa.Expressions.JavaScript/Features/JavaScriptFeature.cs
Line coverage
100%
Covered lines: 33
Uncovered lines: 0
Coverable lines: 33
Total lines: 97
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
.ctor(...)100%11100%
get_JintOptions()100%11100%
ConfigureJintOptions(...)100%11100%
ConfigureHostedServices()100%11100%
Configure()100%11100%
Apply()100%11100%

File(s)

/home/runner/work/elsa-core/elsa-core/src/modules/Elsa.Expressions.JavaScript/Features/JavaScriptFeature.cs

#LineLine coverage
 1using Elsa.Caching.Features;
 2using Elsa.Common.Features;
 3using Elsa.Expressions.Features;
 4using Elsa.Extensions;
 5using Elsa.Features.Abstractions;
 6using Elsa.Features.Attributes;
 7using Elsa.Features.Services;
 8using Elsa.Expressions.JavaScript.Activities;
 9using Elsa.Expressions.JavaScript.Contracts;
 10using Elsa.Expressions.JavaScript.Extensions;
 11using Elsa.Expressions.JavaScript.HostedServices;
 12using Elsa.Expressions.JavaScript.Options;
 13using Elsa.Expressions.JavaScript.Providers;
 14using Elsa.Expressions.JavaScript.Services;
 15using Elsa.Expressions.JavaScript.TypeDefinitions.Contracts;
 16using Elsa.Expressions.JavaScript.TypeDefinitions.Services;
 17using Elsa.Workflows;
 18using Microsoft.Extensions.DependencyInjection;
 19
 20namespace Elsa.Expressions.JavaScript.Features;
 21
 22/// <summary>
 23/// Installs JavaScript integration.
 24/// </summary>
 25[DependsOn(typeof(MediatorFeature))]
 26[DependsOn(typeof(ExpressionsFeature))]
 27[DependsOn(typeof(MemoryCacheFeature))]
 28public class JavaScriptFeature : FeatureBase
 29{
 30    /// <inheritdoc />
 23531    public JavaScriptFeature(IModule module) : base(module)
 32    {
 23533    }
 34
 35    /// <summary>
 36    /// Configures the Jint options.
 37    /// </summary>
 57538    private Action<JintOptions> JintOptions { get; set; } = _ => { };
 39
 40    public JavaScriptFeature ConfigureJintOptions(Action<JintOptions> configure)
 41    {
 242        JintOptions += configure;
 243        return this;
 44    }
 45
 46    /// <inheritdoc />
 47    public override void ConfigureHostedServices()
 48    {
 23549        ConfigureHostedService<RegisterVariableTypesWithJavaScriptHostedService>();
 23550    }
 51
 52    /// <inheritdoc />
 53    public override void Configure()
 54    {
 23555        Module.AddFastEndpointsAssembly<JavaScriptFeature>();
 23556    }
 57
 58    /// <inheritdoc />
 59    public override void Apply()
 60    {
 23561        Services.Configure(JintOptions);
 62
 63        // JavaScript services.
 23564        Services
 23565            .AddScoped<IJavaScriptEvaluator, JintJavaScriptEvaluator>()
 23566            .AddScoped<ITypeDefinitionService, TypeDefinitionService>()
 23567            .AddExpressionDescriptorProvider<JavaScriptExpressionDescriptorProvider>()
 23568            ;
 69
 70        // Type definition services.
 23571        Services
 23572            .AddScoped<ITypeDefinitionService, TypeDefinitionService>()
 23573            .AddScoped<ITypeDescriber, TypeDescriber>()
 23574            .AddScoped<ITypeDefinitionDocumentRenderer, TypeDefinitionDocumentRenderer>()
 23575            .AddSingleton<ITypeAliasRegistry, TypeAliasRegistry>()
 23576            .AddFunctionDefinitionProvider<CommonFunctionsDefinitionProvider>()
 23577            .AddFunctionDefinitionProvider<ActivityOutputFunctionsDefinitionProvider>()
 23578            .AddFunctionDefinitionProvider<RunJavaScriptFunctionsDefinitionProvider>()
 23579            .AddTypeDefinitionProvider<CommonTypeDefinitionProvider>()
 23580            .AddTypeDefinitionProvider<VariableTypeDefinitionProvider>()
 23581            .AddTypeDefinitionProvider<WorkflowVariablesTypeDefinitionProvider>()
 23582            .AddVariableDefinitionProvider<WorkflowVariablesVariableProvider>()
 23583            ;
 84
 85        // Handlers.
 23586        Services.AddNotificationHandlersFrom<JavaScriptFeature>();
 87
 88        // Activities.
 47089        Module.UseWorkflowManagement(management => management.AddActivity<RunJavaScript>());
 90
 91        // Type Script definitions.
 23592        Services.AddFunctionDefinitionProvider<InputFunctionsDefinitionProvider>();
 93
 94        // UI property handlers.
 23595        Services.AddScoped<IPropertyUIHandler, RunJavaScriptOptionsProvider>();
 23596    }
 97}