Newbie question about IntegerMinValueRuleArgs - cslava20

Newbie question about IntegerMinValueRuleArgs - cslava20

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


RumbleCow posted on Monday, April 06, 2009

I've read the first two chapters of 'Expert VB 2005 Business Objects' in an attempt to determine if the architecture will work for our enterprise.

IntegerMinValueRuleArgs appears to imply 'required'.  Is there a way to require an integer property to range from 1 - 999999 if there is a value (other than zero or a character)?  I would prefer to not alter the csla.

Thanks in advance (and sorry for the newbee question).

triplea replied on Monday, April 06, 2009

If I remember well you specify the min value only - not a range. Considering that the check will be done on an int type property, characters will be excluded anyway.

If you want more tailor made validation then you can create your own. E.g.

private int _myInt;
public int MyInt { ... }

protected override override AddBusinessRules()
{
      ValidationRules.AddRule<MyClass>(IsValidRange<MyClass>, "MyInt");
      ...
}

private static bool IsValidRange<T>(T target, Csla.Validation.RuleArgs e)
   where T : MyClass
{
      if (target._myInt < 1 && target._myInt > 99999)
      {
            e.Description = "Invalid number";
            return false;
      }
      return true;
}

If this is going to be used frequently you can of course centralize it.This is just a quick dirty example.

 

RumbleCow replied on Monday, April 06, 2009

Good point on the range.  I was too quick to post without checking my statements.  Character values do trip the validation (as it should).  I've built a simple screen to check this. 

The question still stands...will a separate validation method need to be written to allow blank integers or  can the existing IntegerMinValue and IntegerMaxValue methods be used for both required and non-required integers.

This is our first time using an open source architecture and trying to get a feel for how much modification is or should be required for use and what this will mean when we move to future versions.

Thanks much for your patients with a newbie

RockfordLhotka replied on Monday, April 06, 2009

The business and validation rule subsystem in CSLA .NET is designed to be extended with your own rule methods.

There is absolutely no reason to alter CSLA to add new or different rules - they can be added to your individual business classes, or as a library of rules for your application.

It would be the rare application that didn't need some rules beyond the very basic ones in CommonRules. I suspect every real application out there includes a number of other rule methods to provide other validation or business behaviors based on the application's requirements.

RumbleCow replied on Monday, April 06, 2009

I realize this can be done outside the CSLA but was checking to see if this functionality existed in the current 'common' validation classes-- don't read any attitude into that statement.  To me, this common validation would not be business-specific and we would add it to the CSLA.  I am attempting to determine what 'common' validation functionality might need to be added by us and how best to do this to make migration to future releases to CSLA as seamless as possible. Any recommendations, or suggested reading on implementing open source would be appreciated.

ajj3085 replied on Monday, April 06, 2009

Well, usually it's recommended to have a library that subclasses each Csla BO class, in case you need to add behavior to all your BOs.  Such a library would also be a good place for the rules you're looking to add.

RockfordLhotka replied on Monday, April 06, 2009

I’m not sure you are understanding what I’m saying.

 

CSLA includes 6-8 ‘common rule’ implementations. In practice, they can’t meet everyone’s needs. Obviously even something as a “minimum value” rule has an element of controversy.

 

I have no desire to write “the ultimate set of rules in the universe”, so instead I created a subsystem by which organizations can implement their own rule libraries to meet their needs. No one needs to (or should) modify CSLA itself to create their rule library. That would be silly. They can (and should) create their library as part of their codebase.

 

Rocky

 

RumbleCow replied on Monday, April 06, 2009

Makes perfect sense.  Thanks for your help.

Copyright (c) Marimer LLC