Singleton rule per session ? #352
-
Hello, In this example, 5 istances of class DummyRule1 are created: `public class DummyRule1 : Rule { .... } var repo = new RuleRepository(); var typeRule1 = typeof(DummyRule1); repo.Load((loader) => loader.From(typeRule1, typeRule1, typeRule1, typeRule1, typeRule1)); var session = repo.Compile().CreateSession();` Is there a way to enforce that constraint or it's just a responsibility of who fills the rulerepository ? Thank you |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
@GianLucaBagnoli there are legit use cases where the same rule type may need to be instantiated multiple times. E.g. if the class is parameterized, and each instance is actually a different rule with different conditions. So, the RuleRepository cannot make assumptions about the rules' uniqueness solely based on the type. You are right - it is the caller's responsibility to ensure logical uniqueness of the rules in the repository. |
Beta Was this translation helpful? Give feedback.
@GianLucaBagnoli there are legit use cases where the same rule type may need to be instantiated multiple times. E.g. if the class is parameterized, and each instance is actually a different rule with different conditions. So, the RuleRepository cannot make assumptions about the rules' uniqueness solely based on the type. You are right - it is the caller's responsibility to ensure logical uniqueness of the rules in the repository.