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).
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.
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
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.
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
Copyright (c) Marimer LLC