Self Managing Business Objects

Self Managing Business Objects

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


Matt posted on Friday, November 02, 2007

In working with csla and having to give business objects to wpf designers I have found a need to have a class that automatically does things, the most common of which is saving. This poses a problem though as the Clone() method must be used when saving and I haven't found a way to have the business object do this internally. Has anyone found a need to have an object like this where things just happen automagically as items are added/removed or properties have changed? If you have found a need how did you tackle the problem of the cloning with the saving?

Yang replied on Friday, November 02, 2007

You can implement a base class like this that overrides the Save method by invoking the clone first before actually saving the object. You can derive your business objects that needs to be saved "automagically" from this class. There is also a collection class that does save after each edit. Please see EditableRootListBase.

Imports Csla

Public MustInherit Class ClonedSavingBusinessBase(Of T As Csla.BusinessBase(Of T))

Inherits BusinessBase(Of T)

Public Overrides Function Save() As T

Dim cloneT As T = Clone()

Return cloneT.Save()

End Function

End Class

JoeFallon1 replied on Friday, November 02, 2007

Also be sure to check the newer versions of CSLA as Rocky has added AutoClone to the DataPortal. I think it is false for now by default and you can changeit tot True. In the next version he is going to make it True by Default because it should have always been that way.

Joe

 

rsbaker0 replied on Saturday, November 03, 2007

On a related note, beware of EditableRootListBase unless you have the new AutoClone feature turned *on*.

I found that otherwise, ERLB would clone objects that weren't even dirty, perhaps when leaving a grid to edit the same item on a property sheet. At that point, the object in the ERLB and object on the form were two different objects.

With AutoClone, the object doesn't get cloned/saved unless it is dirty. Much better.

Copyright (c) Marimer LLC