internal static BusinessRuleManager GetRulesForType(Type type, string ruleSet)
        {
            if (ruleSet == ApplicationContext.DefaultRuleSet)
            {
                ruleSet = null;
            }

            BusinessRuleManager result = null;
            var key = new RuleSetKey {
                Type = type, RuleSet = ruleSet
            };
            var found = false;

            try
            {
                found = _perTypeRules.TryGetValue(key, out result);
            }
            catch
            { /* failure will drop into !found block */ }
            if (!found)
            {
                lock (_perTypeRules)
                {
                    if (!_perTypeRules.TryGetValue(key, out result))
                    {
                        result = new BusinessRuleManager();
                        _perTypeRules.Add(key, result);
                    }
                }
            }
            return(result);
        }
        internal static BusinessRuleManager GetRulesForType(Type type, string ruleSet)
        {
            if (ruleSet == ApplicationContext.DefaultRuleSet)
            {
                ruleSet = null;
            }

            BusinessRuleManager result = null;
            var key = new RuleSetKey {
                Type = type, RuleSet = ruleSet
            };

            if (!_perTypeRules.TryGetValue(key, out result))
            {
                lock (_perTypeRules)
                {
                    if (!_perTypeRules.TryGetValue(key, out result))
                    {
                        result = new BusinessRuleManager();
                        _perTypeRules.Add(key, result);
                    }
                }
            }
            return(result);
        }
Beispiel #3
0
        /// <summary>
        /// Associates a business rule with the business object.
        /// </summary>
        /// <param name="rule">Rule object.</param>
        /// <param name="ruleSet">Rule set name.</param>
        public void AddRule(IBusinessRule rule, string ruleSet)
        {
            var typeRules = BusinessRuleManager.GetRulesForType(_target.GetType(), ruleSet);

            typeRules.Rules.Add(rule);
        }