2022-05-26 15:05:36 +00:00
|
|
|
using Elsa.Liquid.Configuration;
|
2022-05-26 10:47:31 +00:00
|
|
|
using Elsa.Liquid.Implementations;
|
|
|
|
|
using Elsa.Liquid.Options;
|
|
|
|
|
using Elsa.Liquid.Services;
|
2022-05-26 15:05:36 +00:00
|
|
|
using Elsa.ServiceConfiguration.Services;
|
2022-01-12 11:37:40 +00:00
|
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
|
|
|
|
2022-05-26 10:47:31 +00:00
|
|
|
namespace Elsa.Liquid.Extensions;
|
2022-01-12 11:37:40 +00:00
|
|
|
|
2022-05-26 10:47:31 +00:00
|
|
|
public static class DependencyInjectionExtensions
|
2022-01-12 11:37:40 +00:00
|
|
|
{
|
2022-05-26 15:05:36 +00:00
|
|
|
public static IServiceConfiguration UseLiquid(this IServiceConfiguration configuration, Action<LiquidConfigurator>? configure = default)
|
2022-01-12 11:37:40 +00:00
|
|
|
{
|
2022-05-26 15:05:36 +00:00
|
|
|
configuration.Configure(configure);
|
|
|
|
|
return configuration;
|
2022-01-12 11:37:40 +00:00
|
|
|
}
|
2022-05-26 15:05:36 +00:00
|
|
|
|
2022-01-12 11:37:40 +00:00
|
|
|
public static IServiceCollection AddLiquidFilter<T>(this IServiceCollection services, string name) where T : class, ILiquidFilter
|
|
|
|
|
{
|
|
|
|
|
services.Configure<FluidOptions>(options => options.FilterRegistrations[name] = typeof(T));
|
|
|
|
|
services.AddScoped<T>();
|
|
|
|
|
return services;
|
|
|
|
|
}
|
2022-05-26 15:05:36 +00:00
|
|
|
|
2022-01-12 11:37:40 +00:00
|
|
|
public static IServiceCollection RegisterLiquidTag(this IServiceCollection services, Action<LiquidParser> configure)
|
|
|
|
|
{
|
|
|
|
|
services.Configure<FluidOptions>(options => options.ParserConfiguration.Add(configure));
|
|
|
|
|
return services;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Enables access to .NET configuration via the Configuration keyword.
|
|
|
|
|
/// Do not enable this option if you execute user supplied (or otherwise untrusted) workflows.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public static IServiceCollection EnableLiquidConfigurationAccess(this IServiceCollection services)
|
|
|
|
|
{
|
|
|
|
|
services.Configure<FluidOptions>(options => options.AllowConfigurationAccess = true);
|
|
|
|
|
return services;
|
|
|
|
|
}
|
|
|
|
|
}
|