Business Rule Instance

Business Rule Instance

Old forum URL:

st3fanus posted on Thursday, July 25, 2013

Hi all..

I read on ebook that said :

one rule instance is shared across all instances of business type.

I want to know a foundation / reason to said that ?


this is my current understanding, I hope Rocky or someone else could explain to me  to update my understanding :


we insert code to add a rule in

protected override void AddBusinessRules()


BusinessRules.AddRule(new MyRule( ..... ));


and then when each my business type instances is created this method is called, Is it not mean that I add a new MyRule for each my business instance ?


thanks a lot






JonnyBee replied on Friday, July 26, 2013

CSLA 4 has type rules only. Which means that CSLA keeps a list of type and registered rules internally. 

The AddBusinessRules method will only be called when there is no entry in the list for the given type (typically once) in your application and each Rule instance should be viewed as a Singelton - shared instance - for all instances of youe business object. Each time you create a BusinessObject there is code in the constructor to check if rules has been registered - and if not call AddBusinessRules. 

This is to simplify the serialization size (BusinessRules is NOT serialized, only BrokenRules) and reduce the memory footprint.

So you do not add a new MyRule to your instance - you register the MyRule rule for this Type.

Copyright (c) Marimer LLC