Hi!
I am finding a strange problem! I have created a BusinessObject From BusinessBase. I have added 3 Instance Rules in the AddCustomRules Method.
These Rules are invoked the First time an object is created By using the new factory method. But in all subsequent calls to New Factory method My Custom Rules are not checked. I am wondering what might be the problem.
Further describing the problem. I have an Invoice Object which is having 3 Instance Rules Checking for the Exisitence of a Guid Value in 3 properties which is not equal to null or NewGuid. The 3 Properties are og Type Nullable<Guid>.
Now in the AddCustomRules Method I have added these rules as Instance Rules. The First time an instance of the Invoice is Created Using NewInvoice the Rules are checked. But on all subsequent calls to NewInvoice() a new object is constructed and returned but the instance rules are not checked.
Do you have validationrules.checkrules call in your code?
Just making sure…
Sergey Barskiy
Senior Consultant
office: 678.405.0687 |
mobile: 404.388.1899
Microsoft Worldwide Partner of the Year | Custom
Development Solutions, Technical Innovation
From: Manu Singhal
[mailto:cslanet@lhotka.net]
Sent: Sunday, May 18, 2008 4:51 AM
To: Sergey Barskiy
Subject: Re: [CSLA .NET] Custom Rule Checking
Further describing the problem. I have an Invoice Object which is having 3
Instance Rules Checking for the Exisitence of a Guid Value in 3 properties
which is not equal to null or NewGuid. The 3 Properties are og Type
Nullable<Guid>.
Now in the AddCustomRules Method I have added these rules as Instance Rules.
The First time an instance of the Invoice is Created Using NewInvoice the Rules
are checked. But on all subsequent calls to NewInvoice() a new object is
constructed and returned but the instance rules are not checked.
Just curious - but why are you using Instance rules?
Do the rules vary with each invoice?
I have not seen many examples of instance rules and would like to better understand why they are used.
Joe
Well My custom rule involves checking if the Guid is NewGuid or Null. It fails if one of them is true. I have created a method for the same and then added it as instance rule.
Is there any other way in which this type of business rule can be used?
To My Surprise the rules work fine when the first instance is created using NewInvoice() Mehtod. But on all subsequent calls to NewInvoice() the rules are not checked
Ok I have changed the Business Object Design by removing the validation logic from Instance Rule. and Adding a static Method to check the rules.
But I sincerely dont understand yet why was the instance rule i added was being checked the first time i created the object using New Factory method and on all subsequent calls to New Factory Method the instance rules were not checked.
Copyright (c) Marimer LLC