achieving persistence ignorance with nhibernate

18
Achieving Persistence Ignorance with NHibernate James Kovacs JamesKovacs.com [email protected]

Upload: chico

Post on 24-Feb-2016

38 views

Category:

Documents


0 download

DESCRIPTION

Achieving Persistence Ignorance with NHibernate. James Kovacs JamesKovacs.com [email protected]. What is Persistence Ignorance?. POCO – Plain Old CLR Object No persistence-related code Only business logic public class Customer {      public string Name { get; } - PowerPoint PPT Presentation

TRANSCRIPT

Page 1: Achieving Persistence Ignorance with  NHibernate

Achieving Persistence Ignorancewith NHibernate

James KovacsJamesKovacs.com

[email protected]

Page 2: Achieving Persistence Ignorance with  NHibernate
Page 3: Achieving Persistence Ignorance with  NHibernate
Page 4: Achieving Persistence Ignorance with  NHibernate
Page 5: Achieving Persistence Ignorance with  NHibernate
Page 6: Achieving Persistence Ignorance with  NHibernate
Page 7: Achieving Persistence Ignorance with  NHibernate
Page 8: Achieving Persistence Ignorance with  NHibernate
Page 9: Achieving Persistence Ignorance with  NHibernate
Page 10: Achieving Persistence Ignorance with  NHibernate

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) {}}

Page 11: Achieving Persistence Ignorance with  NHibernate

Why is Persistence Ignorance Important?

• Separation of concerns• Single responsibility• Loose coupling• Testability• Re-use

Page 12: Achieving Persistence Ignorance with  NHibernate

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) {}}

Page 13: Achieving Persistence Ignorance with  NHibernate

NHibernate API

Configuration Class for bootstrapping NHibernate

ISessionFactory Factory for creating sessions

ISession Roughly analogous to a database connection

ITransaction Abstracts underlying transaction semantics

IQuery String-based query API aka HQL

ICriteria Object-based query API aka Criteria

Page 14: Achieving Persistence Ignorance with  NHibernate

Key Features for PI

• Persistence by reachability• Automatic dirty checking• Transparent lazy loading

Page 15: Achieving Persistence Ignorance with  NHibernate

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)

Page 16: Achieving Persistence Ignorance with  NHibernate
Page 17: Achieving Persistence Ignorance with  NHibernate
Page 18: Achieving Persistence Ignorance with  NHibernate

Questions

James [email protected]