| | | 1 | | using Elsa.Expressions.Liquid.Contracts; |
| | | 2 | | using Elsa.Expressions.Liquid.Options; |
| | | 3 | | using Elsa.Expressions.Liquid.Services; |
| | | 4 | | |
| | | 5 | | // ReSharper disable once CheckNamespace |
| | | 6 | | namespace Microsoft.Extensions.DependencyInjection; |
| | | 7 | | |
| | | 8 | | public static class DependencyInjectionExtensions |
| | | 9 | | { |
| | | 10 | | /// <summary> |
| | | 11 | | /// Register a custom Liquid filter. |
| | | 12 | | /// </summary> |
| | | 13 | | public static IServiceCollection AddLiquidFilter<T>(this IServiceCollection services, string name) where T : class, |
| | | 14 | | { |
| | 4 | 15 | | services.Configure<FluidOptions>(options => options.FilterRegistrations[name] = typeof(T)); |
| | 2 | 16 | | services.AddScoped<T>(); |
| | 2 | 17 | | return services; |
| | | 18 | | } |
| | | 19 | | |
| | | 20 | | /// <summary> |
| | | 21 | | /// Register a custom Liquid tag. |
| | | 22 | | /// </summary> |
| | | 23 | | public static IServiceCollection RegisterLiquidTag(this IServiceCollection services, Action<LiquidParser> configure) |
| | | 24 | | { |
| | 0 | 25 | | services.Configure<FluidOptions>(options => options.ParserConfiguration.Add(configure)); |
| | 0 | 26 | | return services; |
| | | 27 | | } |
| | | 28 | | |
| | | 29 | | /// <summary> |
| | | 30 | | /// Enables access to .NET configuration via the Configuration keyword. |
| | | 31 | | /// Do not enable this option if you execute user supplied (or otherwise untrusted) workflows. |
| | | 32 | | /// </summary> |
| | | 33 | | public static IServiceCollection EnableLiquidConfigurationAccess(this IServiceCollection services) |
| | | 34 | | { |
| | 0 | 35 | | services.Configure<FluidOptions>(options => options.AllowConfigurationAccess = true); |
| | 0 | 36 | | return services; |
| | | 37 | | } |
| | | 38 | | } |