| | | 1 | | using Elsa.Expressions.JavaScript.Contracts; |
| | | 2 | | using Elsa.Workflows.Management.Options; |
| | | 3 | | using Microsoft.Extensions.Hosting; |
| | | 4 | | using Microsoft.Extensions.Options; |
| | | 5 | | |
| | | 6 | | namespace Elsa.Expressions.JavaScript.HostedServices; |
| | | 7 | | |
| | | 8 | | /// <summary> |
| | | 9 | | /// Registers variable types with the JavaScript type alias registry |
| | | 10 | | /// </summary> |
| | | 11 | | public class RegisterVariableTypesWithJavaScriptHostedService : IHostedService |
| | | 12 | | { |
| | | 13 | | private readonly ITypeAliasRegistry _typeAliasRegistry; |
| | | 14 | | private readonly IOptions<ManagementOptions> _managementOptions; |
| | | 15 | | |
| | | 16 | | /// <summary> |
| | | 17 | | /// Initializes a new instance of the <see cref="RegisterVariableTypesWithJavaScriptHostedService"/> class. |
| | | 18 | | /// </summary> |
| | 1 | 19 | | public RegisterVariableTypesWithJavaScriptHostedService(ITypeAliasRegistry typeAliasRegistry, IOptions<ManagementOpt |
| | | 20 | | { |
| | 1 | 21 | | _typeAliasRegistry = typeAliasRegistry; |
| | 1 | 22 | | _managementOptions = managementOptions; |
| | 1 | 23 | | } |
| | | 24 | | |
| | | 25 | | /// <inheritdoc /> |
| | | 26 | | public Task StartAsync(CancellationToken cancellationToken) |
| | | 27 | | { |
| | 60 | 28 | | foreach (var variableDescriptor in _managementOptions.Value.VariableDescriptors) |
| | 29 | 29 | | _typeAliasRegistry.RegisterType(variableDescriptor.Type, variableDescriptor.Type.Name); |
| | | 30 | | |
| | 1 | 31 | | return Task.CompletedTask; |
| | | 32 | | } |
| | | 33 | | |
| | | 34 | | /// <inheritdoc /> |
| | 2 | 35 | | public Task StopAsync(CancellationToken cancellationToken) => Task.CompletedTask; |
| | | 36 | | } |