public RuleHandlingDelegate <TContext> Build() { if (built) { throw new InvalidOperationException("Chain can only be built once"); } var next = new RuleHandlingDelegate <TContext>(context => Task.CompletedTask); while (components.Any()) { var component = components.Pop(); next = component(next); } built = true; return(next); }
private RuleHandlingDelegate <TContext> createDelegate <TRule>(RuleHandlingDelegate <TContext> next) { var ruleType = typeof(TRule); MethodInfo methodInfo = getValidInvokeMethodInfo(ruleType); //Constructor parameters object[] constructorArguments = new object[] { next }; object[] dependencies = getDependencies(ruleType, GetService); if (dependencies.Any()) { constructorArguments = constructorArguments.Concat(dependencies).ToArray(); } //Create the rule instance using the constructor arguments (including dependencies) object rule = GetService(ruleType, constructorArguments); //return the delegate for the rule return((RuleHandlingDelegate <TContext>)methodInfo .CreateDelegate(typeof(RuleHandlingDelegate <TContext>), rule)); }
public IsValidCupomRule(RuleHandlingDelegate <ApplyDiscountContext> next, ISalesRepository salesRepository) : base(next) { _salesRepository = salesRepository; }
public FirstOrderDiscountRule(RuleHandlingDelegate <ApplyDiscountContext> next) : base(next) { }