Skip to content

dxmi/XAF_Non-Persistent-Objects-Editing-Demo

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

53 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Files to look at:

How to implement CRUD operations for Non-Persistent Objects stored remotely

Scenario

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 FilterController is enabled for these objects, so their list view and lookup list view can be filtered. 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.

Solution

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 in a single atomic operation.

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 simplified implementation of IDataStore as storage for Non-Persistent Object data.

Common Components

The following classes are used to provide a common functionality for all non-persistent objects used in the demo.

NonPersistentObjectBase

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.

NonPersistentObjectSpaceHelper

This is a helper class that subscribes to the XafApplication.ObjectSpaceCreated event and performs a common setup of NonPersistentObjectSpace. This usually includes creating and linking additional object spaces, and setting up object adapters. Adapters are registered in the Application.SetupComplete event handler in module code.

TransientNonPersistentObjectAdapter

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 uses a factory to handle specific object types and their storage. It also maintains an identity map (ObjectMap) for NonPersistentObjectSpace.

NonPersistentObjectFactoryBase

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.

DataStoreMapper

This is a set of classes that represents external storage. These classes can be used by a factory to store object data in XPO's IDataStore storage. The classes are:

  • DataStoreObjectLoader - loads objects by their keys and collections of objects.
  • DataStoreObjectSaver - saves data of modified objects.
  • DataStoreMapping - describes how objects are mapped to tables and columns.

About

.NET, Frameworks (XAF & XPO), eXpressApp Framework

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published