CSLA .NET

From Rockford Lhotka's Expert C# 2005 and VB 2005 Business Objects books

Welcome to CSLA .NET Sign in | Join | Help
in Search

Custom Rule Checking

Last post 05-28-2008, 2:13 AM by Manu Singhal. 5 replies.
Sort Posts: Previous Next
  •  05-15-2008, 6:18 AM 23590

    Custom Rule Checking

    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.

     

     

  •  05-18-2008, 3:50 AM 23637 in reply to 23590

    Re: 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.

     

     

  •  05-18-2008, 8:34 AM 23638 in reply to 23637

    RE: Custom Rule Checking

    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.

     

     



  •  05-19-2008, 8:42 AM 23649 in reply to 23638

    Re: RE: Custom Rule Checking

    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

     

  •  05-19-2008, 9:54 PM 23680 in reply to 23649

    Re: RE: Custom Rule Checking

    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

  •  05-28-2008, 2:13 AM 23821 in reply to 23680

    Re: RE: Custom Rule Checking

    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.

     

View as RSS news feed in XML

Please contact Magenic for your .NET consulting and CSLA .NET mentoring needs.
Please consider making a donation to help support the ongoing development of CSLA .NET.

Make donation through PayPal - it's fast, free and secure!
Why donate?
Powered by Community Server, by Telligent Systems