Hi guys I have noticed a strange behavior on one of the rules which is that when I override the Protected Sub Execute its not being called when the rule is being called or added into the Collection Of rules only the Sub New of the Rule Class is being Invoked, Any ideas why this is happing,
Serveral possible reasons:
1. Usage of RuleSets allows you to define separate sets of Rules for a BusinessObject. Rules that do not exist in the "current" RuleSet will not be called during validation.
2. Rules with priority > BusinessRules.ProcessThroughPriority will not be called if a previous Rule added ErrorResult (ie: RuleSeverity.Error).
3. A previous rule has ShortCircuited rule processing for this Field.
You should be able to see all the registered rules for a typ i the debugger in <bo>.BusinessRules._typeRules
Hi thanks for the reply My problem is not that its not being called the problem is that its being called but not the "Execute Sub Method " only the sub new of the class is being called
It's been a while, but I believe that under CSLA 4, rule objects are shared across business-object instances - which means they are only created once. So you would see your constructor run, probably fairly early in your application lifecycle, and possibly before any business objects actually need to be validated. But it would only run once.
Jonny's recommendations still apply - you may have other rules that are precluding this rule from being run. Priority settings, along with possible short-circuiting of rules, could cause your rule not to run. Or using RuleSets could exclude your rule from the set of currently-processing rules. These are the most likely places to start your investigation.
If you could supply the code for a sample rule and how you register the rule in the Business Object we may identify the problem more precisely.
Its a very Simple vb Class here is the example
Public Class Transaction
Inherits BusinessBase(Of Transaction)
Protected Overrides Sub AddBusinessRules()
BusinessRules.AddRule(New RequierdInterest(InterestRateProperty, IsSale))
BusinessRules.AddRule(New RequierdInterest(TransactionTypeProperty, IsSale))
Private Class InterestRateCalculater
Public Sub New(ByVal prop As Csla.Core.IPropertyInfo)
THIS SUB IS NOT BEING CALLED WHEN EVER THIS RULE IS BEING EXECUTED ANY HELP WHY THIS METHOD IS NOT BEING CALLED NOT BY ADDING NOR BY RUNING THIS RULE
Protected Overrides Sub Execute(context As Csla.Rules.RuleContext)
'My code here context.Complete()
'My code here
The InterestRateCalculator is expected to be registered to IdProperty
Thus, your constructor on the rule is not correct:
Public Sub New(ByVal prop As Csla.Core.IPropertyInfoMy
and should be:
Execute should not be called when adding the rule.
The instance of the new rule is added to a RulesMangaer for all instances of this business object type.
The Execute method will be called
Copyright (c) Marimer LLC