2023-07-17 19:43:35 +00:00
|
|
|
using Elsa.Common.Features;
|
2023-03-03 21:47:23 +00:00
|
|
|
using Elsa.Expressions.Contracts;
|
2022-05-27 10:36:39 +00:00
|
|
|
using Elsa.Expressions.Features;
|
2022-12-31 15:16:43 +00:00
|
|
|
using Elsa.Extensions;
|
2022-05-27 10:36:39 +00:00
|
|
|
using Elsa.Features.Abstractions;
|
|
|
|
|
using Elsa.Features.Attributes;
|
|
|
|
|
using Elsa.Features.Services;
|
2023-02-13 11:15:20 +00:00
|
|
|
using Elsa.JavaScript.Contracts;
|
2022-05-26 15:05:36 +00:00
|
|
|
using Elsa.JavaScript.Expressions;
|
2023-04-19 19:28:58 +00:00
|
|
|
using Elsa.JavaScript.Extensions;
|
2023-08-13 10:35:15 +00:00
|
|
|
using Elsa.JavaScript.Options;
|
2022-05-26 15:05:36 +00:00
|
|
|
using Elsa.JavaScript.Providers;
|
|
|
|
|
using Elsa.JavaScript.Services;
|
2023-02-13 11:15:20 +00:00
|
|
|
using Elsa.JavaScript.TypeDefinitions.Contracts;
|
|
|
|
|
using Elsa.JavaScript.TypeDefinitions.Providers;
|
|
|
|
|
using Elsa.JavaScript.TypeDefinitions.Services;
|
2022-05-26 15:05:36 +00:00
|
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
|
|
|
|
2022-05-27 10:36:39 +00:00
|
|
|
namespace Elsa.JavaScript.Features;
|
2022-05-26 15:05:36 +00:00
|
|
|
|
2022-12-30 12:11:29 +00:00
|
|
|
/// <summary>
|
|
|
|
|
/// Installs JavaScript integration.
|
|
|
|
|
/// </summary>
|
2022-05-27 10:36:39 +00:00
|
|
|
[DependsOn(typeof(MediatorFeature))]
|
|
|
|
|
[DependsOn(typeof(ExpressionsFeature))]
|
|
|
|
|
public class JavaScriptFeature : FeatureBase
|
2022-05-26 15:05:36 +00:00
|
|
|
{
|
2022-12-30 12:11:29 +00:00
|
|
|
/// <inheritdoc />
|
2022-05-27 10:36:39 +00:00
|
|
|
public JavaScriptFeature(IModule module) : base(module)
|
2022-05-26 15:05:36 +00:00
|
|
|
{
|
|
|
|
|
}
|
2023-08-13 10:35:15 +00:00
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Configures the Jint options.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public Action<JintOptions> JintOptions { get; set; } = _ => { };
|
|
|
|
|
|
2023-03-02 20:21:50 +00:00
|
|
|
/// <inheritdoc />
|
|
|
|
|
public override void Apply()
|
|
|
|
|
{
|
2023-08-13 10:35:15 +00:00
|
|
|
Services.Configure(JintOptions);
|
|
|
|
|
|
2023-03-02 20:21:50 +00:00
|
|
|
// JavaScript services.
|
2022-05-26 15:05:36 +00:00
|
|
|
Services
|
|
|
|
|
.AddSingleton<IExpressionSyntaxProvider, JavaScriptExpressionSyntaxProvider>()
|
|
|
|
|
.AddSingleton<IJavaScriptEvaluator, JintJavaScriptEvaluator>()
|
2023-01-19 13:09:58 +00:00
|
|
|
.AddSingleton<ITypeDefinitionService, TypeDefinitionService>()
|
2022-12-30 12:11:29 +00:00
|
|
|
.AddExpressionHandler<JavaScriptExpressionHandler, JavaScriptExpression>()
|
|
|
|
|
;
|
|
|
|
|
|
2023-03-02 20:21:50 +00:00
|
|
|
// Type definition services.
|
2023-01-19 13:09:58 +00:00
|
|
|
Services
|
|
|
|
|
.AddSingleton<ITypeDefinitionService, TypeDefinitionService>()
|
|
|
|
|
.AddSingleton<ITypeDescriber, TypeDescriber>()
|
|
|
|
|
.AddSingleton<ITypeDefinitionDocumentRenderer, TypeDefinitionDocumentRenderer>()
|
|
|
|
|
.AddSingleton<ITypeAliasRegistry, TypeAliasRegistry>()
|
2023-04-19 19:28:58 +00:00
|
|
|
.AddFunctionDefinitionProvider<CommonFunctionsDefinitionProvider>()
|
2023-06-09 20:10:56 +00:00
|
|
|
.AddFunctionDefinitionProvider<ActivityOutputFunctionsDefinitionProvider>()
|
2023-04-19 19:28:58 +00:00
|
|
|
.AddTypeDefinitionProvider<CommonTypeDefinitionProvider>()
|
|
|
|
|
.AddTypeDefinitionProvider<VariableTypeDefinitionProvider>()
|
2023-01-31 10:01:39 +00:00
|
|
|
;
|
2023-03-02 20:21:50 +00:00
|
|
|
|
|
|
|
|
// Handlers.
|
|
|
|
|
Services.AddNotificationHandlersFrom<JavaScriptFeature>();
|
2022-05-26 15:05:36 +00:00
|
|
|
}
|
|
|
|
|
}
|