elsa-core/src/modules/Elsa.CSharp/Features/CSharpFeature.cs

52 lines
1.4 KiB
C#
Raw Normal View History

using Elsa.Common.Features;
using Elsa.CSharp.Contracts;
using Elsa.CSharp.Expressions;
using Elsa.CSharp.Options;
using Elsa.CSharp.Providers;
using Elsa.CSharp.Services;
using Elsa.Expressions.Contracts;
using Elsa.Expressions.Features;
using Elsa.Extensions;
using Elsa.Features.Abstractions;
using Elsa.Features.Attributes;
using Elsa.Features.Services;
using Microsoft.Extensions.DependencyInjection;
namespace Elsa.CSharp.Features;
/// <summary>
/// Installs C# integration.
/// </summary>
[DependsOn(typeof(MediatorFeature))]
[DependsOn(typeof(ExpressionsFeature))]
public class CSharpFeature : FeatureBase
{
/// <inheritdoc />
public CSharpFeature(IModule module) : base(module)
{
}
/// <summary>
/// Configures the <see cref="RoslynOptions"/>.
/// </summary>
public Action<CSharpOptions> RoslynOptions { get; set; } = _ => { };
/// <inheritdoc />
public override void Apply()
{
Services.Configure(RoslynOptions);
// C# services.
Services
.AddSingleton<IExpressionSyntaxProvider, CSharpExpressionSyntaxProvider>()
.AddSingleton<ICSharpEvaluator, CSharpEvaluator>()
.AddExpressionHandler<CSharpExpressionHandler, CSharpExpression>()
;
// Handlers.
Services.AddNotificationHandlersFrom<CSharpFeature>();
// Activities.
Module.AddActivitiesFrom<CSharpFeature>();
}
}