9using System.Collections.Generic;
12using System.Runtime.Loader;
25 private static Lazy<System.Collections.Concurrent.ConcurrentDictionary<RuleSetKey, Tuple<string, BusinessRuleManager>>> _perTypeRules =
26 new Lazy<System.Collections.Concurrent.ConcurrentDictionary<RuleSetKey, Tuple<string, BusinessRuleManager>>>();
28 private static Lazy<System.Collections.Concurrent.ConcurrentDictionary<RuleSetKey,
BusinessRuleManager>> _perTypeRules =
29 new Lazy<System.Collections.Concurrent.ConcurrentDictionary<RuleSetKey,
BusinessRuleManager>>();
37 var key =
new RuleSetKey { Type = type, RuleSet = ruleSet };
40 var rulesInfo = _perTypeRules.Value
43 (t) => AssemblyLoadContextManager.CreateCacheInstance(type,
new BusinessRuleManager(), OnAssemblyLoadContextUnload)
46 return rulesInfo.Item2;
56 internal static void CleanupRulesForType(Type type)
61 var typeRules = _perTypeRules.Value.Where(value => value.Key.Type == type);
62 foreach (var key
in typeRules)
63 _perTypeRules.Value.TryRemove(key.Key, out _);
69 return GetRulesForType(type,
null);
72 private class RuleSetKey
74 public Type Type {
get;
set; }
75 public string RuleSet {
get;
set; }
77 public override bool Equals(
object obj)
79 if (!(obj is RuleSetKey other))
82 return this.Type.Equals(other.Type) && RuleSet == other.RuleSet;
85 public override int GetHashCode()
87 return (this.Type.FullName + RuleSet).GetHashCode();
94 public List<IBusinessRuleBase>
Rules {
get;
private set; }
104 Rules =
new List<IBusinessRuleBase>();
108 private static void OnAssemblyLoadContextUnload(AssemblyLoadContext context)
111 AssemblyLoadContextManager.RemoveFromCache(_perTypeRules.Value, context,
true);
Provides consistent context information between the client and server DataPortal objects.
const string DefaultRuleSet
The default RuleSet name
Manages the list of rules for a business type.
bool Initialized
Gets or sets a value indicating whether the rules have been initialized.
List< IBusinessRuleBase > Rules
Gets the list of rule objects for the business type.