| | | 1 | | using Elsa.Expressions.CSharp.Notifications; |
| | | 2 | | using Elsa.Expressions.CSharp.Options; |
| | | 3 | | using Elsa.Mediator.Contracts; |
| | | 4 | | using JetBrains.Annotations; |
| | | 5 | | using Microsoft.CodeAnalysis.Scripting; |
| | | 6 | | using Microsoft.Extensions.Options; |
| | | 7 | | |
| | | 8 | | namespace Elsa.Expressions.CSharp.Handlers; |
| | | 9 | | |
| | | 10 | | /// <summary> |
| | | 11 | | /// This handler adds assemblies and namespaces from the <see cref="CSharpOptions"/> to the <see cref="ScriptOptions"/>. |
| | | 12 | | /// </summary> |
| | | 13 | | [UsedImplicitly] |
| | | 14 | | public class AddAssembliesAndReferencesFromOptions : INotificationHandler<EvaluatingCSharp> |
| | | 15 | | { |
| | | 16 | | private readonly CSharpOptions _options; |
| | | 17 | | |
| | | 18 | | /// <summary> |
| | | 19 | | /// Initializes a new instance of the <see cref="AddAssembliesAndReferencesFromOptions"/> class. |
| | | 20 | | /// </summary> |
| | 319 | 21 | | public AddAssembliesAndReferencesFromOptions(IOptions<CSharpOptions> options) |
| | | 22 | | { |
| | 319 | 23 | | _options = options.Value; |
| | 319 | 24 | | } |
| | | 25 | | |
| | | 26 | | /// <inheritdoc /> |
| | | 27 | | public Task HandleAsync(EvaluatingCSharp notification, CancellationToken cancellationToken) |
| | | 28 | | { |
| | 0 | 29 | | notification.ConfigureScriptOptions(scriptOptions => scriptOptions |
| | 0 | 30 | | .AddReferences(_options.Assemblies) |
| | 0 | 31 | | .AddImports(_options.Namespaces)); |
| | | 32 | | |
| | 0 | 33 | | return Task.CompletedTask; |
| | | 34 | | } |
| | | 35 | | } |