Custom Rule Checking

Custom Rule Checking

Old forum URL: forums.lhotka.net/forums/t/4851.aspx


Manu Singhal posted on Thursday, May 15, 2008

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.

 

 

Manu Singhal replied on Sunday, May 18, 2008

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.

 

 

sergeyb replied on Sunday, May 18, 2008

Do you have validationrules.checkrules call in your code?  Just making sure…

 

Sergey Barskiy

Senior Consultant

office: 678.405.0687 | mobile: 404.388.1899

cid:_2_0648EA840648E85C001BBCB886257279
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.

 

 



JoeFallon1 replied on Monday, May 19, 2008

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

 

Manu Singhal replied on Monday, May 19, 2008

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

Manu Singhal replied on Wednesday, May 28, 2008

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