I've recently seen something interesting occurring with CSLA and thought I'd stick a note in here about it. Basically, when we save with a clone, any events hooked to it are lost.
I typically use the ListChanged and Saved events to evaluate a list (for example) and set properties on controls. It might look like this:
Private Sub SomeList_Saved(ByVal sender As Object, ByVal e As Csla.Core.SavedEventArgs) Handles _SomeList.Saved
<set control properties approriately>
End Sub
Well, when saving with a clone, the objects stop responding to events. The listener gets lost somewhere. Only way we've found to make this continue to work seems a little hokey, but it works:
If _someList.IsSaveable Then
Dim temp As SomeList = _someList.Clone()
temp = _someList.Clone()
temp.ApplyEdit()
_someList = temp.Save()
'These next two lines address an issue that occurs when cloning an object.
'The listener can no longer hear the events.
RemoveHandler _someList.ListChanged, AddressOf _someList_ListChanged
AddHandler _someList.ListChanged, AddressOf _someList_ListChanged
End If
Not sure I understand just why we have to remove and add the handler, but it does work. Simply adding it again won't do.
Print | posted on Tuesday, August 14, 2007 7:07 PM