locked
Generic transaction abstraction for NHibernate and Entity Framework RRS feed

  • Question

  • I am looking for an example of how to use some generic transaction abstraction, making it easy to switch Repository implementations between e.g. NHibernate or Entity Framework.

    (Regarding the mentioned "Repository" I am talking about a DDD repository, and if the reader may not be aware of the DDD repository, then please see http://en.wikipedia.org/wiki/Domain-driven_design )

    I believe a solution might involve System.Transactions.TransactionScope or the Spring.AOP Transaction attribute.
    If possible, I would like to find some good example code illustrating how client code can be truly independing of the current repository implementation, not needing to be modified when replacing the repository implementation.

    An interesting example would be an application layer method which instantiates two Repository implementations (probably by using some dependency injection framework to avoid the coupling to concrete repository implementation classes) which both will invoke some persisting code (Inserts/Updates/Deletes) and then the client code in the application layer should either commit the changes explicit (or implicit commit/rollback with Spring AOP).

    / Tomas
    Monday, March 15, 2010 3:12 PM

All replies

  • I don't have an answer to your question but last time I created a prototype with NHibernate I believe it didn't support TransactionScope all that well.  I don't remember if had to do with me using Oracle as the back end or not.  It seems to me that TransactionScope (or any container that would use it) is the only way to really decouple a transaction from your DAL implementation.  Also it seems like a necessity to begin with if you're attempting to hold a transaction at the Service/Application layer spanning multiple BLL classes that in turn instantiate their own DAL objects.
    Monday, March 15, 2010 5:21 PM
  • easy, just make your system a config-file free, registration-free plug-in host and merely implement all behaviour as plugins in a totally auto-discoverable plug-in system . then all you do is xcopy in the relevant repositoryIMPL plug-in .

     


    MickyD | http://mickyd.wordpress.com/ Help others by voting my post as 'Helpful' if you think it is so.
    Sunday, April 4, 2010 1:04 PM
  • easy, just make your system a config-file free, registration-free plug-in host and merely implement all behaviour as plugins in a totally auto-discoverable plug-in system . then all you do is xcopy in the relevant repositoryIMPL plug-in .

     


    MickyD | http://mickyd.wordpress.com/ Help others by voting my post as 'Helpful' if you think it is so.

    Hi, Micky. Thank you very much for sharing. I am a new hand. Would you please provide some more detailed article or guides? Very appreciated.
    Friday, July 2, 2010 5:24 PM