Search

Simple Persistence

SimplePersistence is a very thin and simple persistence layer that binary serializes entities to files. All files are kept below your executable's path in a sub path called 'SimplePersistence\<FullName of entity's type>'. It's main use is for small applications that only need to persist smaller objects from a simple domain model (see Beware! below).

SimplePersistence is not currently maintained anymore! If you'd like to take over the project contact me via http://simplabs.com/#contact.

Usage

To use the framework, all you have to do is implement one interface to help the persistence layer find the entity's IDs.

class Customer : IPersistable {

  private int? id;

  public int? IPersistable.Identifier {
    get {
      return id;
    }
    set {
      id = value;
    }
  }

}
When your entities are ready for persistence, simply call the PersistenceService:

Simplabs.SimplePersistence.PersistenceService.Persist<TestEntity>(entity);
The service does also have methods like Remove(), Load() etc.

Beware!

Using serialization for persistence has 2 major drawbacks:
  • The persisted data won't survive changes in the code: If you have persisted an instance of class 'Entity' and then change this class' implementation, you won't be able to restore an instance of this class from the persisted data.
  • Serialization of an object serializes the COMPLETE OBJECT GRAPH. This means if you serialize an instance of class 'Customer' that holds a reference to an instance of class 'Order' and later change that order and serialize it too, then when you load the customer again, the changes made to the order later on won't be reflected in the customer's referenced order.
Anyway, the framework is still pretty usable for smaller applications that don't need to migrate data from different versions and that have a rather simple object model.

Extensible

SimplePersistence is extensible. The binary serializer might be replaced with the xml formatter or even a formatter for a custom format or one that would allow the persisted data to survive changes in the entity's implementation. If you'd like to extend the library, open a ticket, get the source or just drop me note!

Author

Copyright © 2008 Marco Otte-Witte (http://simplabs.com), released under the MIT license
Last edited Feb 23 2010 at 11:18 AM by marcoow, version 25
Updating...
© 2006-2012 Microsoft | Get Help | Privacy Statement | Terms of Use | Code of Conduct | Advertise With Us | Version 2012.1.11.18365