| | 1 | | using System.Linq.Expressions; |
| | 2 | |
|
| | 3 | | namespace Fluorite.Strainer.Services.Filtering; |
| | 4 | |
|
| | 5 | | /// <summary> |
| | 6 | | /// Represents a workflow, that when provided with context produces a filtering expression. |
| | 7 | | /// </summary> |
| | 8 | | public class FilterExpressionWorkflow : IFilterExpressionWorkflow |
| | 9 | | { |
| | 10 | | private readonly IReadOnlyCollection<IFilterExpressionWorkflowStep> _steps; |
| | 11 | |
|
| | 12 | | /// <summary> |
| | 13 | | /// Initializes a new instance of the <see cref="FilterExpressionWorkflow"/> class. |
| | 14 | | /// </summary> |
| | 15 | | /// <param name="steps"> |
| | 16 | | /// The workflow steps being its basis. |
| | 17 | | /// </param> |
| 2 | 18 | | public FilterExpressionWorkflow(IReadOnlyCollection<IFilterExpressionWorkflowStep> steps) |
| | 19 | | { |
| 2 | 20 | | _steps = Guard.Against.Null(steps); |
| 2 | 21 | | } |
| | 22 | |
|
| | 23 | | /// <inheritdoc/> |
| | 24 | | /// <exception cref="ArgumentNullException"> |
| | 25 | | /// <paramref name="workflowContext"/> is <see langword="null"/>. |
| | 26 | | /// </exception> |
| | 27 | | public Expression Run(FilterExpressionWorkflowContext workflowContext) |
| | 28 | | { |
| 1 | 29 | | Guard.Against.Null(workflowContext); |
| | 30 | |
|
| 4 | 31 | | foreach (var step in _steps) |
| | 32 | | { |
| 1 | 33 | | step.Execute(workflowContext); |
| | 34 | | } |
| | 35 | |
|
| 1 | 36 | | return workflowContext.FinalExpression!; |
| | 37 | | } |
| | 38 | | } |