I have just started looking at CSLA for Silverlight. I have the Expert C# 2008 Bus Obj book (and 2005 and original version too even though I never read them :-) ). So I am starting with CSLA 4 Beta 1.
I was going to ask if my situation warranted the use of per instance rules but I just read in another post by Rocky that per instance rules have been eliminated in v4 due to large overhead.
I will set up my scenario anyway and maybe someone can tell me if I will still be able to accomplish my goal. I am trying to recreate some existing functionality in a 10+ year old C++/DCOM medical records system so I am limited and what I can change.
In current system, properties of the patient record and the current logged in user drive all other field requirements. This is all user configurable. In the below example, nothing is hard-coded; patient types, patient phases, and user types are all database driven and configurable by my customer.
So for example, my customer can configure system to say if patient is of type 'inpatient' and currently in phase 'initial intake' and the user is of type 'intake clerk', then the Last Name field is required.
But if the patient is changed to phase 'billing intake' and the user is of type 'billing admin', then the Last Name and SSN are required. Changing the type/phase/user type does not need to change the requirements immediately/dynamically -- after reload of object is fine.
It gets a little worse because any child record owned by the patient (a 10 node deep and very wide hierarchy of child records exists under the patient) will also need to know the patient's type and phase in order to properly enforce the child record's requirements.
Because of lack of per-instance rules, not only can I not add the rules dynamically to instance of object but I don't think I have access to other properties of object either in the per type rules. So I don't know if I will be able to access patient's type/phase in the patient record let alone one of the patient's child records.
Is the any hope for me?
Per-type rules have access to the object instance when they are executed. The only reason they are "per-type" is that the rule is created once for the business object type, instead of once for each business object instance.
Per-instance rules are so expensive in terms of performance and memory, that they are nearly useless - which is why they are being removed. While they can be used successfully - with great care and understanding of their negative impact - they just aren't a good idea.
But per-type rules can be very context-sensitive, and they get passed a reference to the target object (that's the first parameter) so they can alter their behavior based on the state of the target object.
You probably won't be able to use the CommonRules implementations - you'll need your own more powerful implementations - but you can do what you are asking.
Thanks Rocky. Sounds like I can make it work. I am just starting out learning CSLA and using InventoryDemo as a starting point. Thanks.
Copyright (c) Marimer LLC