BusinessBase.OnDeserializedHandler negates lazy loading of validation rules

BusinessBase.OnDeserializedHandler negates lazy loading of validation rules

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


tetranz posted on Tuesday, May 01, 2007

Hi all

I'm about to start a new, significantly sized (at least for me) project in CSLA. Before getting into it I thought I better read though most of the book again to refresh my understanding. I never really read the version 2 book properly before.

Rocky, this is probably being overly picky but in Csla.Core.BusinessBase, lazy loading is used in the ValidationRules method to avoid overhead if an object doesn't use validation rules. That sounds good but then in OnDeserializedHandler we do a ValidationRules.SetTarget(this) which would create _validationRules no matter what.

I think OnDeserializedHandler should only do the validation rules stuff if _validationRules != null.

Cheers
Ross

RockfordLhotka replied on Tuesday, May 01, 2007

The purpose of the property isn't really lazy loading, it is to defer creation of the object until after the main business object is created. OK, so that's technically lazy loading... Smile [:)]

But the point is this: a ValidationRules object will always get created. Look through BusinessBase and you'll see it used all over the place. If you avoid all the places it is called, you won't have a functioning business object.

Odds are that you implement AddBusinessRules, which also triggers creation of the object. Even if you don't, you probably call PropertyHasChanged(), whcih triggers it.

tetranz replied on Tuesday, May 01, 2007

Thanks, that makes sense. I was taking the C# book too literally on page 123 Smile [:)]

RockfordLhotka replied on Tuesday, May 01, 2007

Realistically I could (should?) probably just remove the lazy loading in that case, because I'm not sure it gains anything ever...

Copyright (c) Marimer LLC