Skip to content

Rule Initialization

Arif Yayalar (@ayayalar) edited this page Dec 30, 2019 · 2 revisions

Initialize or InitializeAsync methods used for rule-engine related initializations, such as setting up the configuration options Constraint, ExecutionOrder, etc.

Example
class UpdateTotal : RuleAsync<Order>
{
    public override Task InitializeAsync()
    {
        Configuration.Constraint = m => m.FreeShipping;

        IsParallel = true;		
        return Task.FromResult<object>(null);
    }

    public async override Task<IRuleResult> InvokeAsync()
    {
        return await RuleResult.Nil();
    }
}
Model
class Order
{
    public int Id { get; set; }
    public decimal Total { get; set; }
    public bool FreeShipping { get; set; }
}