| | | 1 | | using Elsa.Expressions.Contracts; |
| | | 2 | | using Elsa.Expressions.Features; |
| | | 3 | | using Elsa.Expressions.Options; |
| | | 4 | | using Elsa.Features.Services; |
| | | 5 | | using JetBrains.Annotations; |
| | | 6 | | using Microsoft.Extensions.DependencyInjection; |
| | | 7 | | |
| | | 8 | | // ReSharper disable once CheckNamespace |
| | | 9 | | namespace Elsa.Extensions; |
| | | 10 | | |
| | | 11 | | /// <summary> |
| | | 12 | | /// Extends <see cref="IModule"/>. |
| | | 13 | | /// </summary> |
| | | 14 | | [PublicAPI] |
| | | 15 | | public static class ModuleExtensions |
| | | 16 | | { |
| | | 17 | | /// <summary> |
| | | 18 | | /// Installs the expressions feature. |
| | | 19 | | /// </summary> |
| | | 20 | | /// <param name="module">The module.</param> |
| | | 21 | | /// <param name="configure">A delegate to configure the <see cref="ExpressionsFeature"/>.</param> |
| | | 22 | | public static IModule UseExpressions(this IModule module, Action<ExpressionsFeature>? configure = default) |
| | | 23 | | { |
| | 0 | 24 | | module.Configure(configure); |
| | 0 | 25 | | return module; |
| | | 26 | | } |
| | | 27 | | |
| | | 28 | | /// <summary> |
| | | 29 | | /// Installs the expressions feature. |
| | | 30 | | /// </summary> |
| | | 31 | | /// <param name="services">The services.</param> |
| | | 32 | | public static IServiceCollection AddExpressionDescriptorProvider<T>(this IServiceCollection services) where T: class |
| | | 33 | | { |
| | 4 | 34 | | return services.AddSingleton<IExpressionDescriptorProvider, T>(); |
| | | 35 | | } |
| | | 36 | | |
| | | 37 | | /// <summary> |
| | | 38 | | /// Register type <typeparamref name="T"/> with the specified alias. |
| | | 39 | | /// </summary> |
| | | 40 | | /// <param name="module">The module.</param> |
| | | 41 | | /// <param name="alias">The alias.</param> |
| | | 42 | | /// <typeparam name="T">The type.</typeparam> |
| | | 43 | | public static IModule AddTypeAlias<T>(this IModule module, string alias) |
| | | 44 | | { |
| | 2 | 45 | | module.Services.Configure<ExpressionOptions>(options => options.AddTypeAlias<T>(alias)); |
| | 1 | 46 | | return module; |
| | | 47 | | } |
| | | 48 | | } |