This example demonstrates a possible implementation of editable non-persistent objects that represent data stored remotely and separately from the main XAF application database. These non-persistent objects can be created, deleted, and modified. Their changes are persisted in the external storage. The built-in IsNewObject
function is used in the Appearance rule criterion. This rule disables the key property editor after an Account object is saved.
The following NonPersistentObjectSpace members are used in this example.
Non-persistent objects are kept in an object map. In the ObjectsGetting, ObjectGetting, and ObjectByKeyGetting event handlers, non-persistent objects are looked up and added to the object map. In the Reloaded event handler, the object map is cleared. So, subsequent object queries trigger the creation of new non-persistent object instances. In the ObjectReloading event handler, the state of an existing object is reloaded from the storage.
In the CustomCommitChanges event handler, all object changes are processed and passed to the storage.
The NonPersistentObjectSpace/.AutoSetModifiedOnObjectChange property is set to true
to automatically mark non-persistent objects as modified when the INotifyPropertyChanged.PropertyChanged
event is raised.
We use a 'List' as storage for Non-Persistent Object data.
The following classes are used to provide a common functionality for all non-persistent objects used in the demo.
The abstract base class for all non-persistent objects used in the application. It provides a common implementation of the INotifyPropertyChanged
and IObjectSpaceLink
interfaces and some convenient protected methods.
The adapter for transient (short-living) Non-Persistent business objects. Such objects exist only while their object space is alive. A new adapter instance is created for each non-persistent object space. It subscribes to object space events to manage a subset of object types in a common manner. It also maintains an identity map (ObjectMap
) for NonPersistentObjectSpace
.
Descendants of this class know how to create object instances and transfer data between objects and the storage. It knows nothing about the adapter. It also uses the identity map to avoid creating duplicated objects.