180 likes | 312 Views
Explore the concept of Persistence Ignorance (PI) in the context of NHibernate through James Kovacs' insights. Discover how using Plain Old CLR Objects (POCO) enhances the separation of concerns, promotes single responsibility, and enables loose coupling in application design. Learn the advantages of keeping persistence-related code out of your business logic, improving testability and reusability. This article covers key NHibernate features that support PI, including automatic dirty checking and transparent lazy loading.
E N D
Achieving Persistence Ignorancewith NHibernate James Kovacs JamesKovacs.com jkovacs@post.harvard.edu
What is Persistence Ignorance? • POCO – Plain Old CLR Object • No persistence-related code • Only business logic public class Customer { public string Name { get; } public Location Address { get; } public IList<Order> Orders { get; } public void AddOrder(Order o) {} }
Why is Persistence Ignorance Important? • Separation of concerns • Single responsibility • Loose coupling • Testability • Re-use
NHibernate and PI • No special persistence-related base class • No marker or callback interfaces • No persistence-related attributes • NHibernate domain class: public class Customer { public string Name { get; } public Location Address { get; } public IList<Order> Orders { get; } public void AddOrder(Order o) {} }
Key Features for PI • Persistence by reachability • Automatic dirty checking • Transparent lazy loading
Resources • NHibernate (http://www.nhibernate.org) • NHForge (http://www.nhforge.org) • NHibernate Resources (http://www.hibernate.org/365.html) • NHUsers Google Group (http://groups.google.com/group/nhusers) • ActiveWriter (http://using.castleproject.org/display/Contrib/ActiveWriter) • The Bookshelf (http://www.jameskovacs.com/blog/TheBookshelf.aspx)
Questions James Kovacs JamesKovacs.com jkovacs@post.harvard.edu