Vibrant discussion about CSLA .NET and using the framework to build great business applications.
I am using the latest CSLA.Net 4 and MVC 3. I save BOs in the session and when user enter information, I get hold of the BOs from session and update the object using TryUpdateModel in the controller.
The problem I have is the broken rules doesn't trigger when I read back the BO from session. I mean, when I change the property (in child object) the rule for that property doesn't trigger in SetProperty<>() meathod. I also found that the OnChildChanged event doesn't trigger in the parent object.
Here is my model:
BB (root) with BB (child)
I have overriden OnChildChanged in BB(root) and also have rules in BB(child)
When any property in BB(child) changes by SetProperty<>(), it doesn't break in Rule in BB(child) and also it doesn't break in OnChildChanged of BB(root) while it's in SetProperty. This is the case only when I read back the BB(child) object from Session (HttpContext.Current.Session). When I test this in UnitTest, it's fine and it triggers the events as expected.
I have put [Serializable()] attribute in the Rule class and change the sessionState to InProc in web.config with no luck.
Please could you let me know how I can fix this.
Following my question, I have actually bought the CSLA.Net MVC eBook and I undrestand it's suggested to be stateless and not use Session, but my application has very rich UI and I really need to send Ajax request to bind the model and display the broken rules to the user as they enter information.
Again, the issue I have is the OnChildChanged doesn't triggers in BB(root) when BB(child) property changes by the following ajax request when the BB(child) is read back from session. Also the business rules doesn't trigger in SetProperty like it does when I test the same object in Unit Tests.
Please let me have your suggestion to fix this issue.
I think I found why this is happening. CSLA model binder suspend the
validation rule at the beginning of binding and at the end it runs the
validation only. I think there is a same reason for OnChildChanged event that
is not triggered in the middle of binding. Please let me know if this is
The reason I hooked to OnChildChanged event is just to call
BusinessRules.CheckRules() in the BB(parent). Is there any other way to
validate the parent BO when the child is changed using CslaModelBinder? I can
see the rules is called for BB(child) because the model binder is binding this
object however there is dependent rule in the BB(parent) where needs to be
called when child is changed.
An alternate hook would be the ValidationCompleted event on the child object.
Do you really want to rerun ALL rules in the parent?
Jonny Bekkum, Norway