Note that there are some explanatory texts on larger screens.

plurals
  1. POImplementing repositories using NHibernate and Spring.Net
    text
    copied!<p>I'm trying to get to grips with NHibernate, Fluent NHibernate and Spring.</p> <p>Following domain-driven design principals, I'm writing a standard tiered web application composed of:</p> <ul> <li>a presentation tier (ASP.Net)</li> <li>a business tier, comprising: <ul> <li>an application tier (basically a set of methods made visible to UI tier)</li> <li>repository interfaces and domain components (used by the application tier)</li> </ul></li> <li>A persistence tier (basically the implementation of the repository interfaces defined in the business tier)</li> </ul> <p>I would like help determining a way of instantiating an NHibernate ISession in such a way that it can be shared by multiple repositories over the lifetime of a single request to the business tier. Specifically, I would like to:</p> <ul> <li><p>allow the ISession instance and any transaction to be controlled outwith the repository implementation (perhaps by some aspect of the IOC framework, an interceptor?)</p></li> <li><p>allow the ISession instance to be available to the repositories in a test-friendly manner (perhaps via injection or trough some shared 'context' abstraction)</p></li> <li><p>avoid any unnecessary transactions being created (i.e. when only read-only operations have been executed)</p></li> <li><p>allow me to write tests that use SQLLite</p></li> <li><p>allow me to use Fluent NHibernate</p></li> <li><p>allow the repository implementation to remain ignorant of the host environment. I don't yet know if the businese tier will run in-process with the presentation tier or will be hosted separately under WCF (in IIS), so I don't want to bind my code too closely to a HTTP context (for example).</p></li> </ul> <p>My first attempt to solve this problem had been using the Registry pattern; storing the ISession instance in a ThreadStatic property. However, subsequent reading has suggested that isn't the best solution (as ASP.Net can switch the thread within the page lifecycle, I believe).</p> <p>Any thoughts, part solutions, pattern names, pointers to up-to-date samples (NHibernate 2) will be most gratefully received.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload