2023-03-03 21:47:23 +00:00
|
|
|
using Elsa.Liquid.Contracts;
|
2022-05-26 10:47:31 +00:00
|
|
|
using Elsa.Liquid.Options;
|
|
|
|
|
using Elsa.Liquid.Services;
|
2022-01-12 11:37:40 +00:00
|
|
|
|
2022-12-31 15:16:43 +00:00
|
|
|
// ReSharper disable once CheckNamespace
|
|
|
|
|
namespace Microsoft.Extensions.DependencyInjection;
|
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-12-30 12:11:29 +00:00
|
|
|
/// <summary>
|
|
|
|
|
/// Register a custom Liquid filter.
|
|
|
|
|
/// </summary>
|
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-12-30 12:11:29 +00:00
|
|
|
/// <summary>
|
|
|
|
|
/// Register a custom Liquid tag.
|
|
|
|
|
/// </summary>
|
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;
|
|
|
|
|
}
|
|
|
|
|
}
|