Creating business objects validation with Enterprise Library Validation Block
I’ve been using MS Enterprise Library on a number of projects. There are several blocks that used more often than others. I find validation block particularly useful. However, I usually like to tweak it a bit. The thing I don’t like is when you want to validate an object you require to write a substantial amount of code:
Validator<Customer> validator = ValidationFactory.CreateValidator<Customer>();
ValidationResults results = validator.Validate(customer);
Also it’s possible to create a validator for another type and validate an object with it without any problems, errors or exceptions:
Validator<WRONGCLASS> validator = ValidationFactory.CreateValidator<WRONGCLASS>();
ValidationResults results = validator.Validate(customer);
This feature is for flexibility, however, I haven’t found a need to use it the way it was intended. On the other hand I have encountered a number of situations where developers copy-pasted code responsible for creation of a validator without changing the type of a target object. This results unexpected behaviour during testing.
In order to fix this every business object is derived from a common parent BaseBusinessObject class, which has the following method defined:
public ValidationResults Validate()
{
Validator validator = ValidationFactory.CreateValidator(this.GetType());
return validator.Validate(this);
}
As a result, validating an object is now a lot simpler:
customer.Validate();
Usually it makes sense to have a base business object class anyway, so it’s not much of an overhead.
42 Comments »
RSS feed for comments on this post. TrackBack URL
tips to sell your home
blog topic
Trackback by tips to sell your home — March 26, 2021 @ 11:53 PM
gucci crossbody bags
Alex in a nutshell » Creating business objects validation with Enterprise Library Validation Block
Trackback by gucci crossbody bags — January 16, 2022 @ 9:12 AM
periodic table of elements wallpaper 1920×1080
Alex in a nutshell » Creating business objects validation with Enterprise Library Validation Block
Trackback by periodic table of elements wallpaper 1920x1080 — January 16, 2022 @ 11:12 AM
Biteandswitch`s recent blog post
Alex in a nutshell » Creating business objects validation with Enterprise Library Validation Block
Trackback by Biteandswitch`s recent blog post — January 16, 2022 @ 12:42 PM
try kirmes-werkel.de
Alex in a nutshell » Creating business objects validation with Enterprise Library Validation Block
Trackback by try kirmes-werkel.de — January 16, 2022 @ 12:50 PM
asian movies watch online
Alex in a nutshell » Creating business objects validation with Enterprise Library Validation Block
Trackback by asian movies watch online — January 16, 2022 @ 5:43 PM
hatsan break barrel air rifles
Alex in a nutshell » Creating business objects validation with Enterprise Library Validation Block
Trackback by hatsan break barrel air rifles — January 16, 2022 @ 7:33 PM
mcm handbags
Alex in a nutshell » Creating business objects validation with Enterprise Library Validation Block
Trackback by mcm handbags — January 16, 2022 @ 8:36 PM
find more
Alex in a nutshell » Creating business objects validation with Enterprise Library Validation Block
Trackback by find more — January 16, 2022 @ 10:42 PM
handbags on sale
Alex in a nutshell » Creating business objects validation with Enterprise Library Validation Block
Trackback by handbags on sale — January 17, 2022 @ 10:14 PM
artego blooming elixir
Alex in a nutshell » Creating business objects validation with Enterprise Library Validation Block
Trackback by artego blooming elixir — January 18, 2022 @ 5:15 AM
best sex toys for couples
Alex in a nutshell » Creating business objects validation with Enterprise Library Validation Block
Trackback by best sex toys for couples — January 18, 2022 @ 9:49 AM
small black leather wallet
Alex in a nutshell » Creating business objects validation with Enterprise Library Validation Block
Trackback by small black leather wallet — January 18, 2022 @ 11:59 AM
Portland Leather Tote
Alex in a nutshell » Creating business objects validation with Enterprise Library Validation Block
Trackback by Portland Leather Tote — January 18, 2022 @ 12:47 PM
ego 15″ string Trimmer
Alex in a nutshell » Creating business objects validation with Enterprise Library Validation Block
Trackback by ego 15" string Trimmer — January 18, 2022 @ 2:41 PM
disney princess style collection travel tote
Alex in a nutshell » Creating business objects validation with Enterprise Library Validation Block
Trackback by disney princess style collection travel tote — January 19, 2022 @ 2:09 AM
husqvarna 141 Chainsaw
Alex in a nutshell » Creating business objects validation with Enterprise Library Validation Block
Trackback by husqvarna 141 Chainsaw — January 19, 2022 @ 2:14 AM
building blocks toys
Alex in a nutshell » Creating business objects validation with Enterprise Library Validation Block
Trackback by building blocks toys — January 19, 2022 @ 3:13 PM
Knights Of the round table wallpaper
Alex in a nutshell » Creating business objects validation with Enterprise Library Validation Block
Trackback by Knights Of the round table wallpaper — January 19, 2022 @ 6:13 PM
valentino garavani rockstud top handle shoulder bag
Alex in a nutshell » Creating business objects validation with Enterprise Library Validation Block
Trackback by valentino garavani rockstud top handle shoulder bag — January 19, 2022 @ 7:03 PM
source website
Alex in a nutshell » Creating business objects validation with Enterprise Library Validation Block
Trackback by source website — January 20, 2022 @ 6:45 AM
masai women’s clothing
Alex in a nutshell » Creating business objects validation with Enterprise Library Validation Block
Trackback by masai women's clothing — January 20, 2022 @ 11:07 AM
mens small Leather wallet
Alex in a nutshell » Creating business objects validation with Enterprise Library Validation Block
Trackback by mens small Leather wallet — January 20, 2022 @ 4:21 PM
interruttore tapparelle elettriche
Alex in a nutshell » Creating business objects validation with Enterprise Library Validation Block
Trackback by interruttore tapparelle elettriche — January 21, 2022 @ 5:22 AM
building toys for kids
Alex in a nutshell » Creating business objects validation with Enterprise Library Validation Block
Trackback by building toys for kids — January 21, 2022 @ 2:11 PM
artego colori per capelli
Alex in a nutshell » Creating business objects validation with Enterprise Library Validation Block
Trackback by artego colori per capelli — January 22, 2022 @ 8:36 AM
swiss diver watches
Alex in a nutshell » Creating business objects validation with Enterprise Library Validation Block
Trackback by swiss diver watches — January 22, 2022 @ 9:14 AM
root zte x500 without computer
Alex in a nutshell » Creating business objects validation with Enterprise Library Validation Block
Trackback by root zte x500 without computer — January 22, 2022 @ 5:55 PM
makita angle grinder ga4530
Alex in a nutshell » Creating business objects validation with Enterprise Library Validation Block
Trackback by makita angle grinder ga4530 — January 22, 2022 @ 8:30 PM
try this website
Alex in a nutshell » Creating business objects validation with Enterprise Library Validation Block
Trackback by try this website — January 23, 2022 @ 6:04 PM
Check This Out
Alex in a nutshell » Creating business objects validation with Enterprise Library Validation Block
Trackback by Check This Out — January 24, 2022 @ 12:07 AM
Michael Michael Kors Saffiano Medium Travel Tote
Alex in a nutshell » Creating business objects validation with Enterprise Library Validation Block
Trackback by Michael Michael Kors Saffiano Medium Travel Tote — January 24, 2022 @ 9:17 AM
buy hatsan air rifles
Alex in a nutshell » Creating business objects validation with Enterprise Library Validation Block
Trackback by buy hatsan air rifles — January 24, 2022 @ 12:18 PM
deliveryglasgow.co.uk published a blog post
Alex in a nutshell » Creating business objects validation with Enterprise Library Validation Block
Trackback by deliveryglasgow.co.uk published a blog post — January 24, 2022 @ 3:15 PM
plastic wallpaper table
Alex in a nutshell » Creating business objects validation with Enterprise Library Validation Block
Trackback by plastic wallpaper table — January 25, 2022 @ 10:35 PM
4 inch digital caliper
Alex in a nutshell » Creating business objects validation with Enterprise Library Validation Block
Trackback by 4 inch digital caliper — January 25, 2022 @ 10:37 PM
mitutoyo 8 digital caliper
Alex in a nutshell » Creating business objects validation with Enterprise Library Validation Block
Trackback by mitutoyo 8 digital caliper — January 26, 2022 @ 12:00 PM
Recommended Browsing
Alex in a nutshell » Creating business objects validation with Enterprise Library Validation Block
Trackback by Recommended Browsing — January 26, 2022 @ 12:49 PM
reviews over at Spanning Boundaries
Alex in a nutshell » Creating business objects validation with Enterprise Library Validation Block
Trackback by reviews over at Spanning Boundaries — January 30, 2022 @ 4:29 AM
smart switch iphone
Alex in a nutshell » Creating business objects validation with Enterprise Library Validation Block
Trackback by smart switch iphone — January 30, 2022 @ 1:49 PM
alexander mcqueen small pebbled leather satchel
Alex in a nutshell » Creating business objects validation with Enterprise Library Validation Block
Trackback by alexander mcqueen small pebbled leather satchel — January 30, 2022 @ 3:35 PM
relevant resource site
Alex in a nutshell » Creating business objects validation with Enterprise Library Validation Block
Trackback by relevant resource site — January 31, 2022 @ 7:12 AM