help.axcms.netAxinom Logo
Save Save Chapter Send Feedback

Overview of the AxCMS.net Persistence Framework

AxCMS.net Persistence Framework is a light-weight reusable client-driven library that can be reused in any application based on AxCMS.net.

Is it light-weight, because it covers only 80% of typical database operations, those 80% that can be implemented with a clear and simple code.

It is reusable, because you can override almost every its member, so it is possible to implement the rest 20% of functionality, if you ever need it.

It is client-driven, because it contains only features really needed in AxCMS.net or some of our software projects. 

There are three different approaches or patterns to use the library:

  • Adapter pattern
  • Generic Adapter pattern
  • DbObject pattern

Note: The AxCMS.net Persistance Framework is based on Axinom Framework and uses ConnectionManager and DbSqlQuery classes for database operations. Consult the Axinom Framework documentation for more details about managing connections and using query classes.

Adapter pattern

For every your BL class you implement a pairing adapter class, which handles all database operations.

Advantages of this pattern:

  • You can have several adapters for your object (useful if you want to map the BL class to several slightly different databases or if you want to load different amount of data into the BL object depending on a usage case).
  • You can override any operation (useful if you want to perform some addition actions when the object will be loaded or saved)
  • You don't have to inherit your BL classes from any particular parent.

Disadvantages of this pattern:

  • You have to program an adapter class for every persistant BL class that can lead to a program bloating.
  • Every database operation except loading includes instantiaing of two objects (adapter and the BL object), which is one object too many.

Generic Adapter pattern

You decorate your BL objects with attributes defining mapping to the DB table and DB fields and use single adapter class to handle all your BL objects.

Advantages of this pattern:

  • You don't need to create an adapter for every BL object, if you don't have to.
  • When you add or remove a BL class property, it is easier to do, because you have to change it only in the BL class, not in the adapter.
  • You don't have to inherit your BL classes from any particular parent.

Disadvantage of this pattern is that you have to subclass the generic adapter to be able

  • to map the same object to several slightly different databases.
  • to override database operations differently for different BL classes.
  • to load different amount of information to the same BL object depending on usage case.

AxCMS.net uses Generic Adapter pattern together with subclassing it.

DbObject pattern

You inherit your BL objects from a DbObject, which is at the same time the generic adapter automatically configured for the BL object.

Advantages of this pattern:

  • You don't need to instantiate an adapter to load or save your BL object.
  • You don't need to create an adapter for every BL class.
  • It is easy to override any database operation differently for every BL class.
  • When you add or remove a BL class property, it is easier to do, because you have to change it only in the BL class, not in the adapter.

Disadvantages of this pattern:

  • You have to inherit from DbObject. 
  • You cannot map the object into different databases.
  • You cannot load different amount of data into your objects depending on usage case.
  • Your objects will get many public members from DbObject inherited that clutter and complicate their own interface.