Skip to content

Execution Order

Arif Yayalar (@ayayalar) edited this page Aug 24, 2018 · 1 revision

Rules can have ExecutionOrder to be invoked in a specific order.

Must be set in Initialize, or InitializeAsync method.
Parallel rules cannot have both Parallel and ExecutionOrder specified. Otherwise the parallel option would be ignored.

In the proceeding example, the order of execution would be ValidateProductAmount, and then the ValidateProductName based on the ExecutionOrder specified in the rules.

Example
class ValidateProductAmountAsync : RuleAsync<Order>
{
    public override async Task InitializeAsync()
    {
	if (Model.Id == 1) Configuration.ExecutionOrder = 2;
	await Task.FromResult<IRuleResult>(null);
    }
    public override async Task<IRuleResult> InvokeAsync()
    {
        return await Task.FromResult<IRuleResult>(null);
    }
}
class ValidateProductNameAsync : RuleAsync<Order>
{
    public override async Task InitializeAsync()
    {
	if (Model.Id == 1) Configuration.ExecutionOrder = 1;
	await Task.FromResult<IRuleResult>(null);
    }

    public override async Task<IRuleResult> InvokeAsync()
    {
	return await Task.FromResult<IRuleResult>(null);
    }
}