elsa-workflows / elsa-workflows/elsa-core
Liquid Expression usage in console app
- Dominant language
- C#
- Stars
- 7.9k
- Forks
- 1.5k
- Avg merge
- 15h 22m
- Merged PRs (30d)
- 114
Description
In console app, Liquid Expressions is not working as expected but CSharp Expressions works. Could you please review and help me to handle this.
@cvijayak Thanks.
```
var host = Host.CreateDefaultBuilder()
.ConfigureServices((context, services) =>
{
services.AddMediator();
services.AddElsa(elsa => {
elsa.UseCSharp();
elsa.UseLiquid();
});
services.AddHostedService();
})
.Build();
await host.RunAsync();
```
```
using (var scope = _serviceProvider.CreateScope())
{
var evaluator = scope.ServiceProvider.GetRequiredService();
var executionContext = new ExpressionExecutionContext(scope.ServiceProvider, new MemoryRegister());
executionContext.SetVariable("Name", "Context World");
string e1 = "DateTime.Now.AddDays(1).ToString(\"yyyy-MM-dd\")";
var r1 = await evaluator.EvaluateAsync(new Expression("CSharp", e1), executionContext);
Console.WriteLine(r1);
string e3 = "\"Hello, \" + Variable.Name";
var r3 = await evaluator.EvaluateAsync(new Expression("CSharp", e3), executionContext);
Console.WriteLine(r3); // Hello, Context World
string e4 = "Hello {{ Variables.Name }}";
var r4 = await evaluator.EvaluateAsync(new Expression("Liquid", e4), executionContext);
Console.WriteLine(r4);
}
```
Thanks again.
Contributor guide
Assessment
This issue has not been assessed yet.