<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://nhforge.org/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/"><channel><title>NHibernate and the Unit of Work Pattern</title><link>http://nhforge.org/wikis/patternsandpractices/nhibernate-and-the-unit-of-work-pattern.aspx</link><description>Find articles regarding best practices with NHibernate.</description><dc:language>en-US</dc:language><generator>CommunityServer 2008.5 SP1 (Build: 31106.3070)</generator><item><title>NHibernate and the Unit of Work Pattern</title><link>http://nhforge.org/wikis/patternsandpractices/nhibernate-and-the-unit-of-work-pattern.aspx</link><pubDate>Tue, 23 Sep 2008 20:21:17 GMT</pubDate><guid isPermaLink="false">45f813f2-f1c4-4eda-a619-288e3cadc793:35</guid><dc:creator>gabriel.schenker</dc:creator><comments>http://nhforge.org/wikis/patternsandpractices/nhibernate-and-the-unit-of-work-pattern/comments.aspx</comments><description>Current revision posted to Patterns &amp;amp; Practices by gabriel.schenker on 23/09/2008 05:21:17 p.m.&lt;br /&gt;
&lt;h2&gt;NHibernate and the Unit of Work Pattern&lt;/h2&gt;
&lt;div style="font-size: 90%;"&gt;Filed under: &lt;span style="background: SpringGreen;"&gt;pattern&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;,&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;unit&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;of&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;work&lt;/span&gt;&lt;/div&gt;

&lt;h1&gt;&lt;span style="background: SpringGreen;"&gt;Part&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;1&lt;/span&gt;&lt;/h1&gt;
&lt;h2&gt;Introduction&lt;/h2&gt;
&lt;p&gt;Martin Fowler &lt;a href="http://martinfowler.com/eaaCatalog/unitOfWork.html"&gt;writes&lt;/a&gt;: &lt;/p&gt;
&lt;p&gt;&amp;quot;When you&amp;#39;re pulling data in and out of a database, it&amp;#39;s important to keep 
track of what you&amp;#39;ve changed; otherwise, that data won&amp;#39;t be written back into 
the database. Similarly you have to insert new objects you create and remove any 
objects you delete.&amp;quot;&lt;/p&gt;
&lt;p&gt;and&lt;/p&gt;
&lt;p&gt;&amp;quot;A &lt;b&gt;Unit of Work&lt;/b&gt; keeps track of everything you do during a 
&lt;i&gt;business transaction&lt;/i&gt; that can affect the database. When you&amp;#39;re done, it 
figures out everything that needs to be done to alter the database as a result 
of your work.&amp;quot;&lt;/p&gt;
&lt;p&gt;In NHibernate we have the &lt;b&gt;Session&lt;/b&gt; object which is a Unit of 
Work (UoW) container. The session object keeps track of all objects you load, 
new objects you add, existing objects you delete and changes you make to any of 
these objects. Only when &lt;b&gt;flushing&lt;/b&gt; the session will the database 
be altered (that is: will the necessary create, update and delete statements be 
sent to the database).&lt;/p&gt;
&lt;p&gt;Now, working directly with the NHibernate session object makes absolute 
sense. But some times you rather want to abstract the data manipulation 
interface from a specific infrastructure implementation &amp;agrave; la NHibernate.&lt;/p&gt;
&lt;p&gt;&lt;b&gt;Note&lt;/b&gt;: most of the design ideas and implementation details 
presented here originate from &lt;a href="http://www.ayende.com/"&gt;Ayende&lt;/a&gt;&amp;#39;s 
UnitOfWork implemented in the &lt;b&gt;Rhino.Commons&lt;/b&gt; which you can get 
&lt;a href="http://rhino-tools.svn.sourceforge.net/svnroot/rhino-tools/trunk"&gt;here&lt;/a&gt;.&lt;/p&gt;
&lt;h2&gt;Design and Implementation (TDD)&lt;/h2&gt;
&lt;h3&gt;Some thought about TDD&lt;/h3&gt;
&lt;p&gt;I want to implement a UnitOfWork pattern for NHibernate and I want to do it 
by using &lt;a href="http://en.wikipedia.org/wiki/Test-driven_development"&gt;TDD&lt;/a&gt;. 
For a beginner (like I was myself not so long ago) it seems unnatural at the 
beginning. We introduce a huge overhead you might think. You might also think 
that we have to write at least double the code as when doing the development 
without TDD. But wait until you have to start to debug your application... or 
until the customer wants to have something changed in the application... or 
until you have to re-factor you application... Then you will immediately see and 
feel the benefits of a good test coverage.&lt;/p&gt;
&lt;h3&gt;Attention: Multi-Threading ahead&lt;/h3&gt;
&lt;p&gt;Please not that the implementation presented here is strictly 
&lt;b&gt;NOT&lt;/b&gt; thread safe!!! I want to reduce the complexity of this 
first implementation. But &lt;b&gt;I promise&lt;/b&gt; that in a following post 
I&amp;#39;ll show you how to make the implementation of the unit of work pattern thread 
safe and thus useful for e.g. Web scenarios.&lt;/p&gt;
&lt;h3&gt;The UnitOfWork Class&lt;/h3&gt;
&lt;p&gt;To start with: I want to have an easy way to &lt;b&gt;start&lt;/b&gt; a new 
UoW, in any place of my application have access to the &lt;b&gt;current&lt;/b&gt; 
UoW and &lt;b&gt;commit&lt;/b&gt; the &lt;i&gt;business transaction&lt;/i&gt; represented by 
my UoW. We can do this with a static class called UnitOfWork&lt;/p&gt;
&lt;p&gt;&lt;a&gt;&lt;img src="/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/nhibernate.UoW/UoW-UoW_2D00_class.png" alt="" /&gt;&lt;br /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;The method start creates and returns an instance of a 
&lt;b&gt;UnitOfWorkImplementor&lt;/b&gt; class which implements the interface 
&lt;b&gt;IUnitOfWork&lt;/b&gt;. As you can see then interface IUnitOfWork inherits 
from IDisposable. So we can define that the &lt;i&gt;business transaction&lt;/i&gt; is 
ended when the UoW is disposed. Now, if we do nothing else then nothing should 
happen, that is no changes should be propagated to the database. To commit a 
&lt;i&gt;business transaction&lt;/i&gt; we have to explicitly call a method of the UoW. 
Let&amp;#39;s call this method &lt;b&gt;TransactionalFlush&lt;/b&gt;. In doing so all 
changes recorded by the UoW are committed to the database in one go.&lt;/p&gt;
&lt;p&gt;Now let&amp;#39;s start to implement this! We are doing TDD, aren&amp;#39;t we? So we will 
write our first test (if you are not sure how to best setup a new solution for 
TDD please consult &lt;a href="http://blogs.hibernatingrhinos.com/nhibernate/archive/2008/04/06/how-to-setup-a-new-solution.aspx"&gt;this&lt;/a&gt; 
post). I define a new solution with two projects as follows&lt;/p&gt;
&lt;p&gt;&lt;a&gt;&lt;img src="/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/nhibernate.UoW/UoW-Solution.png" alt="" /&gt;&lt;br /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Add a class UnitOfWork_Fixture.cs to the test project and implement the first 
test like this&lt;/p&gt;
&lt;div&gt;
&lt;div style="border-style:none;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;[TestFixture]&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;&lt;span style="color:#0000ff;"&gt;public&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;class&lt;/span&gt; UnitOfWork_Fixture&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;{&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;    &lt;span style="color:#0000ff;"&gt;private&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;readonly&lt;/span&gt; MockRepository _mocks = &lt;span style="color:#0000ff;"&gt;new&lt;/span&gt; MockRepository();&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;&amp;nbsp;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;    [Test]&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;    &lt;span style="color:#0000ff;"&gt;public&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;void&lt;/span&gt; Can_Start_UnitOfWork()&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;    {&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;        IUnitOfWork uow = UnitOfWork.Start();&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;    }&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;}&lt;/pre&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;Of course this test will not compile since you don&amp;#39;t have the types 
UnitOfWork and IUnitOfWork defined yet. Let &lt;a href="http://www.jetbrains.com/resharper/"&gt;Resharper&lt;/a&gt; create them for you (or 
implement them by hand)&lt;/p&gt;
&lt;div&gt;
&lt;div style="border-style:none;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;&lt;span style="color:#0000ff;"&gt;public&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;static&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;class&lt;/span&gt; UnitOfWork&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;{&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;    &lt;span style="color:#0000ff;"&gt;public&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;static&lt;/span&gt; IUnitOfWork Start()&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;    {&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;        &lt;span style="color:#0000ff;"&gt;throw&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;new&lt;/span&gt; NotImplementedException();&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;    }&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;&amp;nbsp;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;    &lt;span style="color:#0000ff;"&gt;public&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;static&lt;/span&gt; IUnitOfWork Current { get; &lt;span style="color:#0000ff;"&gt;private&lt;/span&gt; set; }&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;}&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;&amp;nbsp;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;&lt;span style="color:#0000ff;"&gt;public&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;interface&lt;/span&gt; IUnitOfWork : IDisposable&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;{&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;}&lt;/pre&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;Now the test will compile but it will fail! Of course, you haven&amp;#39;t 
implemented the Start method so far. In this method we must now create a new UoW 
and return it to the caller. A UoW is a complex beast and should therefore be 
constructed in a factory. So let&amp;#39;s define a factory Interface IUnitOfWorkFactory 
with a method Create which returns a UoW implementing the interface 
IUnitOfWork.&lt;/p&gt;
&lt;div&gt;
&lt;div style="border-style:none;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;&lt;span style="color:#0000ff;"&gt;public&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;interface&lt;/span&gt; IUnitOfWorkFactory&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;{&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;  IUnitOfWork Create();&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;}&lt;/pre&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;since we want to test our UnitOfWork class in isolation we have to mock all 
other dependencies line the unit of work factory. I&amp;#39;ll use 
&lt;b&gt;Rhino.Mocks&lt;/b&gt; as my mocking framework (Please refer to 
documentation &lt;a href="http://www.ayende.com/wiki/Rhino+Mocks+Documentation.ashx"&gt;here&lt;/a&gt;). I 
want to test that when calling the start method of the UnitOfWork class the 
factory gets called. So I extend my test function&lt;/p&gt;
&lt;div&gt;
&lt;div style="border-style:none;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;[Test]&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;&lt;span style="color:#0000ff;"&gt;public&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;void&lt;/span&gt; Can_Start_UnitOfWork()&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;{&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;    var factory = _mocks.DynamicMock&amp;lt;IUnitOfWorkFactory&amp;gt;();&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;    var unitOfWork = _mocks.DynamicMock&amp;lt;IUnitOfWork&amp;gt;();&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;&amp;nbsp;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;    &lt;span style="color:#008000;"&gt;// brute force attack to set my own factory via reflection&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;    var fieldInfo = &lt;span style="color:#0000ff;"&gt;typeof&lt;/span&gt;(UnitOfWork).GetField(&lt;span style="color:#006080;"&gt;&amp;quot;_unitOfWorkFactory&amp;quot;&lt;/span&gt;, &lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;        BindingFlags.Static | BindingFlags.SetField | BindingFlags.NonPublic);&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;    fieldInfo.SetValue(&lt;span style="color:#0000ff;"&gt;null&lt;/span&gt;, factory);&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;&amp;nbsp;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;    &lt;span style="color:#0000ff;"&gt;using&lt;/span&gt;(_mocks.Record())&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;    {&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;        Expect.Call(factory.Create()).Return(unitOfWork);&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;    }&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;    &lt;span style="color:#0000ff;"&gt;using&lt;/span&gt;(_mocks.Playback())&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;    {&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;        var uow = UnitOfWork.Start();&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;    }&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;}&lt;/pre&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;In the first two lines of code I mock the external dependencies of the 
UnitOfWork class. Then I do something you should not do very often (but I have 
good reasons doing so here and I promise it&amp;#39;s the only time I&amp;#39;ll do it in this 
project...). I set a private field of the UnitOfWork class with a value by using 
reflection. I could implement a public setter in the class but as I would only 
need it for this test and I want to keep the class interface as simple as 
possible I chose to do it via reflection.&lt;/p&gt;
&lt;p&gt;In the&amp;nbsp; record phase I define my expectation (namely that the factory create 
method is called) and in the playback phase I invoke the Start method which I 
want to test. The test will compile but fail to execute. I have not yet defined 
the private static field _unitOfWorkFactory and I also do not call the factory. 
So let&amp;#39;s modify our code...&lt;/p&gt;
&lt;div&gt;
&lt;div style="border-style:none;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;&lt;span style="color:#0000ff;"&gt;public&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;static&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;class&lt;/span&gt; UnitOfWork&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;{&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;    &lt;span style="color:#0000ff;"&gt;private&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;static&lt;/span&gt; IUnitOfWorkFactory _unitOfWorkFactory;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;    &lt;span style="color:#0000ff;"&gt;private&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;static&lt;/span&gt; IUnitOfWork _innerUnitOfWork;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;&amp;nbsp;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;    &lt;span style="color:#0000ff;"&gt;public&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;static&lt;/span&gt; IUnitOfWork Start()&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;    {&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;        _innerUnitOfWork = _unitOfWorkFactory.Create();&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;        &lt;span style="color:#0000ff;"&gt;return&lt;/span&gt; _innerUnitOfWork;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;    }&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;&amp;nbsp;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;    &lt;span style="color:#0000ff;"&gt;public&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;static&lt;/span&gt; IUnitOfWork Current { get; &lt;span style="color:#0000ff;"&gt;private&lt;/span&gt; set; }&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;}&lt;/pre&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;now the test will pass.&lt;/p&gt;
&lt;p&gt;Since in all our test regarding the UnitOfWork class we will always need it 
with an injected factory we define a new test fixture with a context setup for 
our specific needs. We put the respective code in the 
&lt;b&gt;SetupContext&lt;/b&gt; and &lt;b&gt;TearDownContext&lt;/b&gt; methods&lt;/p&gt;
&lt;div&gt;
&lt;div style="border-style:none;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;[TestFixture]&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;&lt;span style="color:#0000ff;"&gt;public&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;class&lt;/span&gt; UnitOfWork_With_Factory_Fixture&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;{&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;    &lt;span style="color:#0000ff;"&gt;private&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;readonly&lt;/span&gt; MockRepository _mocks = &lt;span style="color:#0000ff;"&gt;new&lt;/span&gt; MockRepository();&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;    &lt;span style="color:#0000ff;"&gt;private&lt;/span&gt; IUnitOfWorkFactory _factory;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;    &lt;span style="color:#0000ff;"&gt;private&lt;/span&gt; IUnitOfWork _unitOfWork;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;&amp;nbsp;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;    [SetUp]&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;    &lt;span style="color:#0000ff;"&gt;public&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;void&lt;/span&gt; SetupContext()&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;    {&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;        _factory = _mocks.DynamicMock&amp;lt;IUnitOfWorkFactory&amp;gt;();&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;        _unitOfWork = _mocks.DynamicMock&amp;lt;IUnitOfWork&amp;gt;();&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;&amp;nbsp;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;        &lt;span style="color:#008000;"&gt;// brute force attack to set my own factory via reflection&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;        var fieldInfo = &lt;span style="color:#0000ff;"&gt;typeof&lt;/span&gt;(UnitOfWork).GetField(&lt;span style="color:#006080;"&gt;&amp;quot;_unitOfWorkFactory&amp;quot;&lt;/span&gt;,&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;            BindingFlags.Static | BindingFlags.SetField | BindingFlags.NonPublic);&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;        fieldInfo.SetValue(&lt;span style="color:#0000ff;"&gt;null&lt;/span&gt;, _factory);&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;&amp;nbsp;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;        _mocks.BackToRecordAll();&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;        SetupResult.For(_factory.Create()).Return(_unitOfWork);&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;        _mocks.ReplayAll();&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;    }&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;&amp;nbsp;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;    [TearDown]&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;    &lt;span style="color:#0000ff;"&gt;public&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;void&lt;/span&gt; TearDownContext()&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;    {&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;        _mocks.VerifyAll();&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;    }&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;}&lt;/pre&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;&lt;b&gt;Note&lt;/b&gt;: in the second last line of the 
&lt;b&gt;SetupContext&lt;/b&gt; method we define that each time the method Create 
of the factory object is called (by the UnitOfWork Start method) we want it to 
return our predefined mocked _&lt;b&gt;unitOfWork&lt;/b&gt; instance.&lt;/p&gt;
&lt;p&gt;Trying to start a UoW if there is already one active should throw a 
meaningful exception. This is the test&lt;/p&gt;
&lt;div&gt;
&lt;div style="border-style:none;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;[Test]&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;&lt;span style="color:#0000ff;"&gt;public&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;void&lt;/span&gt; Starting_UnitOfWork_if_already_started_throws()&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;{&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;    UnitOfWork.Start();&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;    &lt;span style="color:#0000ff;"&gt;try&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;    {&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;        UnitOfWork.Start();&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;    }&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;    &lt;span style="color:#0000ff;"&gt;catch&lt;/span&gt; (InvalidOperationException ex)&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;    { }&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;}&lt;/pre&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;As a consequence we have to extend our Start method in the UnitOfWork 
class&lt;/p&gt;
&lt;div&gt;
&lt;div style="border-style:none;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;&lt;span style="color:#0000ff;"&gt;public&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;static&lt;/span&gt; IUnitOfWork Start()&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;{&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;    &lt;span style="color:#0000ff;"&gt;if&lt;/span&gt; (_innerUnitOfWork != &lt;span style="color:#0000ff;"&gt;null&lt;/span&gt;)&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;        &lt;span style="color:#0000ff;"&gt;throw&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;new&lt;/span&gt; InvalidOperationException(&lt;span style="color:#006080;"&gt;&amp;quot;You cannot start more than one unit of work at the same time.&amp;quot;&lt;/span&gt;);&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;    &lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;    _innerUnitOfWork = _unitOfWorkFactory.Create();&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;    &lt;span style="color:#0000ff;"&gt;return&lt;/span&gt; _innerUnitOfWork;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;}&lt;/pre&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;Now I have another problem: After the test is finished the static field 
_&lt;b&gt;innerUnitOfWork&lt;/b&gt; of my &lt;b&gt;UnitOfWork&lt;/b&gt; class is set 
to a value other than &lt;b&gt;null&lt;/b&gt;. This will have a undesired side 
effect to the following test. I have to reset this field. Again in this special 
case I&amp;#39;ll do it via reflection to not clutter the interface of my class (static 
classes are difficult more complex to deal with in TDD than non static 
classes...). We do reset our UnitOfWork class in the TearDownContext method&lt;/p&gt;
&lt;div&gt;
&lt;div style="border-style:none;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;[TearDown]&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;&lt;span style="color:#0000ff;"&gt;public&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;void&lt;/span&gt; TearDownContext()&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;{&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;    _mocks.VerifyAll();&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;&amp;nbsp;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;    &lt;span style="color:#008000;"&gt;// assert that the UnitOfWork is reset&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;    var fieldInfo = &lt;span style="color:#0000ff;"&gt;typeof&lt;/span&gt;(UnitOfWork).GetField(&lt;span style="color:#006080;"&gt;&amp;quot;_innerUnitOfWork&amp;quot;&lt;/span&gt;,&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;        BindingFlags.Static | BindingFlags.SetField | BindingFlags.NonPublic);&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;    fieldInfo.SetValue(&lt;span style="color:#0000ff;"&gt;null&lt;/span&gt;, &lt;span style="color:#0000ff;"&gt;null&lt;/span&gt;);&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;}&lt;/pre&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;Next we want to be able to access the current unit of work. As usual we first 
implement a test&lt;/p&gt;
&lt;div&gt;
&lt;div style="border-style:none;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;[Test]&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;&lt;span style="color:#0000ff;"&gt;public&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;void&lt;/span&gt; Can_access_current_unit_of_work()&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;{&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;    IUnitOfWork uow = UnitOfWork.Start();&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;    var current = UnitOfWork.Current;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;    Assert.AreSame(uow, current);&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;}&lt;/pre&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;You can figure out what code you need to implement for the test to pass.&lt;/p&gt;
&lt;p&gt;We also want to assert that when accessing the current UoW if no UoW has been 
started that a meaningful exception is thrown&lt;/p&gt;
&lt;div&gt;
&lt;div style="border-style:none;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;[Test]&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;&lt;span style="color:#0000ff;"&gt;public&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;void&lt;/span&gt; Accessing_Current_UnitOfWork_if_not_started_throws()&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;{&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;    &lt;span style="color:#0000ff;"&gt;try&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;    {&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;        var current = UnitOfWork.Current;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;    }&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;    &lt;span style="color:#0000ff;"&gt;catch&lt;/span&gt; (InvalidOperationException ex)&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;    { }&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;}&lt;/pre&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;now my implementation of the Current property in the UnitOfWork class is as 
follows&lt;/p&gt;
&lt;div&gt;
&lt;div style="border-style:none;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;&lt;span style="color:#0000ff;"&gt;public&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;static&lt;/span&gt; IUnitOfWork Current&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;{&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;    get&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;    {&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;        &lt;span style="color:#0000ff;"&gt;if&lt;/span&gt; (_innerUnitOfWork == &lt;span style="color:#0000ff;"&gt;null&lt;/span&gt;)&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;            &lt;span style="color:#0000ff;"&gt;throw&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;new&lt;/span&gt; InvalidOperationException(&lt;span style="color:#006080;"&gt;&amp;quot;You are not in a unit of work.&amp;quot;&lt;/span&gt;);&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;        &lt;span style="color:#0000ff;"&gt;return&lt;/span&gt; _innerUnitOfWork;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;    }&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;}&lt;/pre&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;Next we want a property on the class which tells us whether a UoW is started 
or not. The test for it&lt;/p&gt;
&lt;div&gt;
&lt;div style="border-style:none;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;[Test]&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;&lt;span style="color:#0000ff;"&gt;public&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;void&lt;/span&gt; Can_test_if_UnitOfWork_Is_Started()&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;{&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;    Assert.IsFalse(UnitOfWork.IsStarted);&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;&amp;nbsp;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;    IUnitOfWork uow = UnitOfWork.Start();&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;    Assert.IsTrue(UnitOfWork.IsStarted);&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;}&lt;/pre&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;It&amp;#39;s getting boring isn&amp;#39;t it... But this is the way &lt;b&gt;TDD&lt;/b&gt; 
works. You always think (hard) on what you need and then you implement the test 
with which you can proof that you get it as you want it. Only then you implement 
the functionality needed to fulfill the test. If you do so you automatically 
follow the &lt;b&gt;YAGNI&lt;/b&gt; principle (you ain&amp;#39;t gona need it) that is you 
only implement the code you really need!&lt;/p&gt;
&lt;p&gt;We can fulfill the test like so&lt;/p&gt;
&lt;div&gt;
&lt;div style="border-style:none;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;&lt;span style="color:#0000ff;"&gt;public&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;static&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;bool&lt;/span&gt; IsStarted&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;{&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;    get { &lt;span style="color:#0000ff;"&gt;return&lt;/span&gt; _innerUnitOfWork != &lt;span style="color:#0000ff;"&gt;null&lt;/span&gt;; }&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;}&lt;/pre&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;The UnitOfWork class is now a perfect wrapper for the NHibernate session 
object. Though for some advance scenarios I would like to have access to the 
session object related to my UoW. As a consequence I&amp;#39;ll implement a read only 
property CurrentSession in the UnitOfWork class. Lets again start with the 
test&lt;/p&gt;
&lt;div&gt;
&lt;div style="border-style:none;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;[Test]&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;&lt;span style="color:#0000ff;"&gt;public&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;void&lt;/span&gt; Can_get_valid_current_session_if_UoW_is_started()&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;{&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;    &lt;span style="color:#0000ff;"&gt;using&lt;/span&gt; (UnitOfWork.Start())&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;    {&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;        ISession session = UnitOfWork.CurrentSession;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;        Assert.IsNotNull(session);&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;    }&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;}&lt;/pre&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;and the implementation&lt;/p&gt;
&lt;div&gt;
&lt;div style="border-style:none;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;&lt;span style="color:#0000ff;"&gt;public&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;static&lt;/span&gt; ISession CurrentSession&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;{&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;    get { &lt;span style="color:#0000ff;"&gt;return&lt;/span&gt; _unitOfWorkFactory.CurrentSession; }&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;    &lt;span style="color:#0000ff;"&gt;internal&lt;/span&gt; set { _unitOfWorkFactory.CurrentSession = &lt;span style="color:#0000ff;"&gt;value&lt;/span&gt;; }&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;}&lt;/pre&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;Note that I have just delegated the call to the factory class. Thus to make 
the test pass I have to add two additional lines to the SetupContext method of 
the test fixture where I mock a session object and setup the result for a call 
to the property CurrentSession of the factory.&lt;/p&gt;
&lt;div&gt;
&lt;div style="border-style:none;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;[SetUp]&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;&lt;span style="color:#0000ff;"&gt;public&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;void&lt;/span&gt; SetupContext()&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;{&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;    _factory = _mocks.DynamicMock&amp;lt;IUnitOfWorkFactory&amp;gt;();&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;    _unitOfWork = _mocks.DynamicMock&amp;lt;IUnitOfWork&amp;gt;();&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;    _session = _mocks.DynamicMock&amp;lt;ISession&amp;gt;();&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;&amp;nbsp;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;    &lt;span style="color:#008000;"&gt;// brute force attack to set my own factory via reflection&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;    var fieldInfo = &lt;span style="color:#0000ff;"&gt;typeof&lt;/span&gt;(UnitOfWork).GetField(&lt;span style="color:#006080;"&gt;&amp;quot;_unitOfWorkFactory&amp;quot;&lt;/span&gt;,&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;        BindingFlags.Static | BindingFlags.SetField | BindingFlags.NonPublic);&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;    fieldInfo.SetValue(&lt;span style="color:#0000ff;"&gt;null&lt;/span&gt;, _factory);&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;&amp;nbsp;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;    _mocks.BackToRecordAll();&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;    SetupResult.For(_factory.Create()).Return(_unitOfWork);&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;    SetupResult.For(_factory.CurrentSession).Return(_session);&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;    _mocks.ReplayAll();&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;}&lt;/pre&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;That&amp;#39;s all we need for the moment regarding the UnitOfWork class. Next topics 
will be the the implementation of the UnitOfWorkFactory class and then of the 
UnitOfWorkImplementor class. The details will be presented in the next &lt;span style="text-decoration: line-through; color: red;"&gt;post&lt;/span&gt; &lt;span style="text-decoration: line-through; color: red;"&gt;to&lt;/span&gt; 
&lt;span style="background: SpringGreen;"&gt;part&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;of&lt;/span&gt; this &lt;span style="text-decoration: line-through; color: red;"&gt;blog&lt;/span&gt;&lt;span style="text-decoration: line-through; color: red;"&gt;.&lt;/span&gt; &lt;span style="text-decoration: line-through; color: red;"&gt;So&lt;/span&gt; &lt;span style="text-decoration: line-through; color: red;"&gt;keep&lt;/span&gt; &lt;span style="text-decoration: line-through; color: red;"&gt;ready..&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;article&lt;/span&gt;.&lt;/p&gt;
&lt;h1&gt;Part 2&lt;/h1&gt;
&lt;h2&gt;Design and Implementation&lt;/h2&gt;
&lt;h3&gt;The Unit Of Work Factory&lt;/h3&gt;
&lt;p&gt;The creation of a unit of work instance is a complex process and as such is a 
good candidate for a factory.&lt;/p&gt;
&lt;p&gt;Since a UoW (Unit of Work) is basically a wrapper around a NHibernate session 
object I&amp;#39;ll need to open such a session whenever I start a new UoW. But to be 
able to get such a session NHibernate has to be configured and a NHibernate 
Session Factory has to be available. The interface of my UoW factory is defined 
as follows&lt;/p&gt;
&lt;p&gt;&lt;img src="/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/nhibernate.UoW/UoW-UoW_2D00_Factory.png" alt="" /&gt;&lt;/p&gt;
&lt;p&gt;I basically have two public methods on my factory. One for the creation of 
the UoW and the second for the disposal of a specific UoW instance. The disposal 
involves also some work and thus justifies the existence of this second factory 
method. The 3 properties &lt;b&gt;Configuration&lt;/b&gt;, 
&lt;b&gt;SessionFactory&lt;/b&gt; and &lt;b&gt;CurrentSession&lt;/b&gt; are there 
mostly for advanced scenarios (and as such could theoretically be omitted in a 
first simple implementation).&lt;/p&gt;
&lt;p&gt;Let&amp;#39;s now write the test for the Create method of the UoW factory 
implementation. At first I prepare a new test fixture class&lt;/p&gt;
&lt;div&gt;
&lt;div style="border-style:none;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;&lt;span style="color:#0000ff;"&gt;using&lt;/span&gt; System;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;&lt;span style="color:#0000ff;"&gt;using&lt;/span&gt; NHibernate;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;&lt;span style="color:#0000ff;"&gt;using&lt;/span&gt; NUnit.Framework;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;&amp;nbsp;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;&lt;span style="color:#0000ff;"&gt;namespace&lt;/span&gt; NHibernateUnitOfWork.Tests&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;{&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;    [TestFixture]&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;    &lt;span style="color:#0000ff;"&gt;public&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;class&lt;/span&gt; UnitOfWorkFactory_Fixture&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;    {&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;        &lt;span style="color:#0000ff;"&gt;private&lt;/span&gt; IUnitOfWorkFactory _factory;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;&amp;nbsp;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;        [SetUp]&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;        &lt;span style="color:#0000ff;"&gt;public&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;void&lt;/span&gt; SetupContext()&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;        {&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;            _factory = (IUnitOfWorkFactory) Activator.CreateInstance(&lt;span style="color:#0000ff;"&gt;typeof&lt;/span&gt; (UnitOfWorkFactory), &lt;span style="color:#0000ff;"&gt;true&lt;/span&gt;);&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;        }&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;    }&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;}&lt;/pre&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;Why the heck do I need the &lt;b&gt;Activator.CreateInstance&lt;/b&gt; to get 
an instance of the factory? Well I decided that the construction of a new 
factory instance should be internal to the assembly implementing the Unit of 
Work pattern. Thus the (default) constructor of the 
&lt;b&gt;UnitOfWorkFactory&lt;/b&gt; class has a modifier 
&lt;b&gt;internal&lt;/b&gt; and as a consequence cannot be used from code outside 
the assembly in which the factory is implemented. But I need an instance when 
testing and thus have to resort to the technique used above.&lt;/p&gt;
&lt;p&gt;Now the question is: &amp;quot;what confirms me that the method Create of the factory 
works as expected?&amp;quot;. I have chosen the following: I expect&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;the method returning a non null instance of type 
&lt;b&gt;IUnitOfWork&lt;/b&gt; 
&lt;/li&gt;
&lt;li&gt;the returned instance having a non null (NHibernate) 
&lt;b&gt;session&lt;/b&gt; 
&lt;/li&gt;
&lt;li&gt;the (NHibernate) session having the Flush Mode set to 
&lt;b&gt;commit&lt;/b&gt; (that is: the session is never flushed except when I 
explicitly commit a transaction - see the NHibernate &lt;a href="http://www.hibernate.org/5.html#A25"&gt;documentation&lt;/a&gt; for any details 
about the Flush Mode) &lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Now the code&lt;/p&gt;
&lt;div&gt;
&lt;div style="border-style:none;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;[Test]&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;&lt;span style="color:#0000ff;"&gt;public&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;void&lt;/span&gt; Can_create_unit_of_work()&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;{&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;    IUnitOfWork implementor = _factory.Create(); &lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;    Assert.IsNotNull(implementor);&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;    Assert.IsNotNull(_factory.CurrentSession);&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;    Assert.AreEqual(FlushMode.Commit, _factory.CurrentSession.FlushMode);&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;}&lt;/pre&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;and the implementation&lt;/p&gt;
&lt;div&gt;
&lt;div style="border-style:none;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;&lt;span style="color:#0000ff;"&gt;public&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;class&lt;/span&gt; UnitOfWorkFactory : IUnitOfWorkFactory&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;{&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;    &lt;span style="color:#0000ff;"&gt;private&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;static&lt;/span&gt; ISession _currentSession;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;    &lt;span style="color:#0000ff;"&gt;private&lt;/span&gt; ISessionFactory _sessionFactory;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;&amp;nbsp;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;    &lt;span style="color:#0000ff;"&gt;internal&lt;/span&gt; UnitOfWorkFactory()&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;    { }&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;&amp;nbsp;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;    &lt;span style="color:#0000ff;"&gt;public&lt;/span&gt; IUnitOfWork Create()&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;    {&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;        ISession session = CreateSession();&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;        session.FlushMode = FlushMode.Commit;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;        _currentSession = session;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;        &lt;span style="color:#0000ff;"&gt;return&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;new&lt;/span&gt; UnitOfWorkImplementor(&lt;span style="color:#0000ff;"&gt;this&lt;/span&gt;, session);&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;    }&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;}&lt;/pre&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;As you can see I first need a new session instance. I then set the flush mode 
to commit and assign the session to an instance variable for further use. 
Finally I return a new instance of the &lt;b&gt;UnitOfWorkImplementor&lt;/b&gt; 
(which implements the interface IUnitOfWork). The constructor of the 
&lt;b&gt;UnitOfWorkImplementor&lt;/b&gt; class requires two parameters, the 
session and a reference to this factory.&lt;/p&gt;
&lt;p&gt;To be able to compile I also have to define the 
&lt;b&gt;UnitOfWorkImplementor&lt;/b&gt; class. Of this class I just implement the 
minimum needed so far&lt;/p&gt;
&lt;div&gt;
&lt;div style="border-style:none;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;&lt;span style="color:#0000ff;"&gt;public&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;class&lt;/span&gt; UnitOfWorkImplementor : IUnitOfWork&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;{&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;    &lt;span style="color:#0000ff;"&gt;private&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;readonly&lt;/span&gt; IUnitOfWorkFactory _factory;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;    &lt;span style="color:#0000ff;"&gt;private&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;readonly&lt;/span&gt; ISession _session;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;&amp;nbsp;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;    &lt;span style="color:#0000ff;"&gt;public&lt;/span&gt; UnitOfWorkImplementor(IUnitOfWorkFactory factory, ISession session)&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;    {&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;        _factory = factory;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;        _session = session;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;    }&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;}&lt;/pre&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;Now back to the implementation of the &lt;b&gt;CreateSession&lt;/b&gt; method. 
To be able to create (and open) a session NHibernate must have been configured 
previously. So I solve this problem first. &lt;/p&gt;
&lt;p&gt;First we add a file &lt;b&gt;hibernate.cfg.xml&lt;/b&gt; to our test project 
and put the following content into it (don&amp;#39;t forget to set the property &amp;#39;Copy to 
Output Directory&amp;#39; of this file to &amp;#39;Copy always&amp;#39;).&lt;/p&gt;
&lt;div&gt;
&lt;div style="border-style:none;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;&lt;span style="color:#0000ff;"&gt;&amp;lt;?&lt;/span&gt;&lt;span style="color:#800000;"&gt;xml&lt;/span&gt; &lt;span style="color:#ff0000;"&gt;version&lt;/span&gt;&lt;span style="color:#0000ff;"&gt;=&amp;quot;1.0&amp;quot;&lt;/span&gt; &lt;span style="color:#ff0000;"&gt;encoding&lt;/span&gt;&lt;span style="color:#0000ff;"&gt;=&amp;quot;utf-8&amp;quot;&lt;/span&gt; ?&lt;span style="color:#0000ff;"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;&lt;span style="color:#0000ff;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color:#800000;"&gt;hibernate-configuration&lt;/span&gt; &lt;span style="color:#ff0000;"&gt;xmlns&lt;/span&gt;&lt;span style="color:#0000ff;"&gt;=&amp;quot;urn:nhibernate-configuration-2.2&amp;quot;&lt;/span&gt;&lt;span style="color:#0000ff;"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;  &lt;span style="color:#0000ff;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color:#800000;"&gt;session-factory&lt;/span&gt;&lt;span style="color:#0000ff;"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;    &lt;span style="color:#0000ff;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color:#800000;"&gt;property&lt;/span&gt; &lt;span style="color:#ff0000;"&gt;name&lt;/span&gt;&lt;span style="color:#0000ff;"&gt;=&amp;quot;connection.provider&amp;quot;&lt;/span&gt;&lt;span style="color:#0000ff;"&gt;&amp;gt;&lt;/span&gt;NHibernate.Connection.DriverConnectionProvider&lt;span style="color:#0000ff;"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color:#800000;"&gt;property&lt;/span&gt;&lt;span style="color:#0000ff;"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;    &lt;span style="color:#0000ff;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color:#800000;"&gt;property&lt;/span&gt; &lt;span style="color:#ff0000;"&gt;name&lt;/span&gt;&lt;span style="color:#0000ff;"&gt;=&amp;quot;dialect&amp;quot;&lt;/span&gt;&lt;span style="color:#0000ff;"&gt;&amp;gt;&lt;/span&gt;NHibernate.Dialect.MsSql2005Dialect&lt;span style="color:#0000ff;"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color:#800000;"&gt;property&lt;/span&gt;&lt;span style="color:#0000ff;"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;    &lt;span style="color:#0000ff;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color:#800000;"&gt;property&lt;/span&gt; &lt;span style="color:#ff0000;"&gt;name&lt;/span&gt;&lt;span style="color:#0000ff;"&gt;=&amp;quot;connection.driver_class&amp;quot;&lt;/span&gt;&lt;span style="color:#0000ff;"&gt;&amp;gt;&lt;/span&gt;NHibernate.Driver.SqlClientDriver&lt;span style="color:#0000ff;"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color:#800000;"&gt;property&lt;/span&gt;&lt;span style="color:#0000ff;"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;    &lt;span style="color:#0000ff;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color:#800000;"&gt;property&lt;/span&gt; &lt;span style="color:#ff0000;"&gt;name&lt;/span&gt;&lt;span style="color:#0000ff;"&gt;=&amp;quot;connection.connection_string&amp;quot;&lt;/span&gt;&lt;span style="color:#0000ff;"&gt;&amp;gt;&lt;/span&gt;Server=(local);Database=Test;Integrated Security=SSPI;&lt;span style="color:#0000ff;"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color:#800000;"&gt;property&lt;/span&gt;&lt;span style="color:#0000ff;"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;    &lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;    &lt;span style="color:#0000ff;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color:#800000;"&gt;property&lt;/span&gt; &lt;span style="color:#ff0000;"&gt;name&lt;/span&gt;&lt;span style="color:#0000ff;"&gt;=&amp;quot;show_sql&amp;quot;&lt;/span&gt;&lt;span style="color:#0000ff;"&gt;&amp;gt;&lt;/span&gt;true&lt;span style="color:#0000ff;"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color:#800000;"&gt;property&lt;/span&gt;&lt;span style="color:#0000ff;"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;  &lt;span style="color:#0000ff;"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color:#800000;"&gt;session-factory&lt;/span&gt;&lt;span style="color:#0000ff;"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;&lt;span style="color:#0000ff;"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color:#800000;"&gt;hibernate-configuration&lt;/span&gt;&lt;span style="color:#0000ff;"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;The above configuration file assumes that you have an &lt;b&gt;SQL Server 
2005&lt;/b&gt; installed on your local machine and that you are using 
&lt;b&gt;integrated security&lt;/b&gt; to authenticate and authorize the access to 
the database. It further assumes that there exists a database called 
&lt;b&gt;&amp;#39;Test&amp;#39;&lt;/b&gt; on this server. To configure NHibernate for other types 
of databases please consult the online documentation &lt;a href="http://www.hibernate.org/361.html"&gt;here&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;Now we define this test method&lt;/p&gt;
&lt;div&gt;
&lt;div style="border-style:none;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;[Test]&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;&lt;span style="color:#0000ff;"&gt;public&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;void&lt;/span&gt; Can_configure_NHibernate()&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;{&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;    var configuration = _factory.Configuration;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;    Assert.IsNotNull(configuration);&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;    Assert.AreEqual(&lt;span style="color:#006080;"&gt;&amp;quot;NHibernate.Connection.DriverConnectionProvider&amp;quot;&lt;/span&gt;, &lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;                    configuration.Properties[&lt;span style="color:#006080;"&gt;&amp;quot;connection.provider&amp;quot;&lt;/span&gt;]);&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;    Assert.AreEqual(&lt;span style="color:#006080;"&gt;&amp;quot;NHibernate.Dialect.MsSql2005Dialect&amp;quot;&lt;/span&gt;, &lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;                    configuration.Properties[&lt;span style="color:#006080;"&gt;&amp;quot;dialect&amp;quot;&lt;/span&gt;]);&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;    Assert.AreEqual(&lt;span style="color:#006080;"&gt;&amp;quot;NHibernate.Driver.SqlClientDriver&amp;quot;&lt;/span&gt;, &lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;                    configuration.Properties[&lt;span style="color:#006080;"&gt;&amp;quot;connection.driver_class&amp;quot;&lt;/span&gt;]);&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;    Assert.AreEqual(&lt;span style="color:#006080;"&gt;&amp;quot;Server=(local);Database=Test;Integrated Security=SSPI;&amp;quot;&lt;/span&gt;, &lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;                    configuration.Properties[&lt;span style="color:#006080;"&gt;&amp;quot;connection.connection_string&amp;quot;&lt;/span&gt;]);&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;}&lt;/pre&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;Here we test whether we can successfully create a configuration and whether 
this configuration contains the attributes we have defined via the NHibernate 
configuration file.&lt;/p&gt;
&lt;p&gt;To fulfill this test we can e.g. implement the following code&lt;/p&gt;
&lt;div&gt;
&lt;div style="border-style:none;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;&lt;span style="color:#0000ff;"&gt;public&lt;/span&gt; Configuration Configuration&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;{&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;    get&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;    {&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;        &lt;span style="color:#0000ff;"&gt;if&lt;/span&gt; (_configuration == &lt;span style="color:#0000ff;"&gt;null&lt;/span&gt;)&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;        {&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;            _configuration = &lt;span style="color:#0000ff;"&gt;new&lt;/span&gt; Configuration();&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;            &lt;span style="color:#0000ff;"&gt;string&lt;/span&gt; hibernateConfig = Default_HibernateConfig;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;            &lt;span style="color:#008000;"&gt;//if not rooted, assume path from base directory&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;            &lt;span style="color:#0000ff;"&gt;if&lt;/span&gt; (Path.IsPathRooted(hibernateConfig) == &lt;span style="color:#0000ff;"&gt;false&lt;/span&gt;)&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;                hibernateConfig = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, hibernateConfig);&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;            &lt;span style="color:#0000ff;"&gt;if&lt;/span&gt; (File.Exists(hibernateConfig))&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;                _configuration.Configure(&lt;span style="color:#0000ff;"&gt;new&lt;/span&gt; XmlTextReader(hibernateConfig));&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;        }&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;        &lt;span style="color:#0000ff;"&gt;return&lt;/span&gt; _configuration;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;    }&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;}&lt;/pre&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;Note that I have defined a class variable _&lt;b&gt;configuration&lt;/b&gt; 
such as that I only execute the configuration logic &lt;i&gt;once&lt;/i&gt; during the 
life time of the application. Note further that in this implementation I assume 
that the configuration of NHibernate is defined via the 
&lt;b&gt;hibernate.cfg.xml&lt;/b&gt; file which must be in the same directory as 
the test assembly.&lt;/p&gt;
&lt;p&gt;As soon as I have a valid configuration I can create a NHibernate session 
factory. Note that this is a &lt;b&gt;rather expensive&lt;/b&gt; operation (takes 
some time depending on the number of entities you are mapping) and thus should 
only be executed once during the life time of the application. The access to the 
NHibernate SessionFactory is &lt;i&gt;thread safe&lt;/i&gt;!&lt;/p&gt;
&lt;p&gt;Let&amp;#39;s write a test for the creation of the SessionFactory.&lt;/p&gt;
&lt;div&gt;
&lt;div style="border-style:none;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;[Test]&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;&lt;span style="color:#0000ff;"&gt;public&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;void&lt;/span&gt; Can_create_and_access_session_factory()&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;{&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;    var sessionFactory = _factory.SessionFactory;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;    Assert.IsNotNull(sessionFactory);&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;    Assert.AreEqual(&lt;span style="color:#006080;"&gt;&amp;quot;NHibernate.Dialect.MsSql2005Dialect&amp;quot;&lt;/span&gt;, sessionFactory.Dialect.ToString());&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;}&lt;/pre&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;This is a rather basic test and only checks whether I can successfully create 
a session factory and whether at least one of its properties is configured as I 
expect it, namely the dialect used.&lt;/p&gt;
&lt;p&gt;The implementation to fulfill the test is rather simple&lt;/p&gt;
&lt;div&gt;
&lt;div style="border-style:none;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;&lt;span style="color:#0000ff;"&gt;public&lt;/span&gt; ISessionFactory SessionFactory&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;{&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;    get&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;    {&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;        &lt;span style="color:#0000ff;"&gt;if&lt;/span&gt; (_sessionFactory == &lt;span style="color:#0000ff;"&gt;null&lt;/span&gt;)&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;            _sessionFactory = Configuration.BuildSessionFactory();&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;        &lt;span style="color:#0000ff;"&gt;return&lt;/span&gt; _sessionFactory;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;    }&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;}&lt;/pre&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;I have defined a class variable _sessionFactory such that I only execute the 
BuildSessionFactory method once during the life time of the application. The 
session factory is created on demand, that is when first needed. At the same 
time this property getter method accesses the previously defined Configuration 
property which in turn triggers the configuration of NHibernate (if not already 
done).&lt;/p&gt;
&lt;p&gt;The last missing piece is the implementation of the CreateSession method 
which now is trivial&lt;/p&gt;
&lt;div&gt;
&lt;div style="border-style:none;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;&lt;span style="color:#0000ff;"&gt;private&lt;/span&gt; ISession CreateSession()&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;{&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;    &lt;span style="color:#0000ff;"&gt;return&lt;/span&gt; SessionFactory.OpenSession();&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;}&lt;/pre&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;I 
want to be able to access the current (open) session via my factory. If there is 
no such session open at the moment a meaningful exception should be raised. To 
test this write 
&lt;/p&gt;
&lt;div&gt;
&lt;div style="border-style:none;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;[Test]&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;&lt;span style="color:#0000ff;"&gt;public&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;void&lt;/span&gt; Accessing_CurrentSession_when_no_session_open_throws()&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;{&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;    &lt;span style="color:#0000ff;"&gt;try&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;    {&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;        var session = _factory.CurrentSession;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;    }&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;    &lt;span style="color:#0000ff;"&gt;catch&lt;/span&gt; (InvalidOperationException)&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;    { }&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;}&lt;/pre&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;and the implementation is easy&lt;/p&gt;
&lt;div&gt;
&lt;div style="border-style:none;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;&lt;span style="color:#0000ff;"&gt;public&lt;/span&gt; ISession CurrentSession&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;{&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;    get&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;    {&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;        &lt;span style="color:#0000ff;"&gt;if&lt;/span&gt; (_currentSession == &lt;span style="color:#0000ff;"&gt;null&lt;/span&gt;)&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;            &lt;span style="color:#0000ff;"&gt;throw&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;new&lt;/span&gt; InvalidOperationException(&lt;span style="color:#006080;"&gt;&amp;quot;You are not in a unit of work.&amp;quot;&lt;/span&gt;);&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;        &lt;span style="color:#0000ff;"&gt;return&lt;/span&gt; _currentSession;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;    }&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;    set { _currentSession = &lt;span style="color:#0000ff;"&gt;value&lt;/span&gt;; }&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;}&lt;/pre&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;The last method to implement is the UoW disposal method. In this method I 
want to reset the CurrentSession to null and then forward the call to our static 
UnitOfWork class (defined in the &lt;a href="http://blogs.hibernatingrhinos.com/nhibernate/archive/2008/04/10/nhibernate-and-the-unit-of-work-pattern.aspx"&gt;first 
part&lt;/a&gt; of this post series) such as that this class can also make an internal 
clean-up. The implementation might look as follows&lt;/p&gt;
&lt;div&gt;
&lt;div style="border-style:none;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;&lt;span style="color:#0000ff;"&gt;public&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;void&lt;/span&gt; DisposeUnitOfWork(UnitOfWorkImplementor adapter)&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;{&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;    CurrentSession = &lt;span style="color:#0000ff;"&gt;null&lt;/span&gt;;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;    UnitOfWork.DisposeUnitOfWork(adapter);&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;}&lt;/pre&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;That&amp;#39;s all we have to do for now regarding the UoW factory. Again we have 
implemented it in a TDD way. When we later re-factor our implementation to make 
it thread-safe this TDD approach will be a huge benefit since we have a complete 
test coverage of out code.&lt;/p&gt;
&lt;h3&gt;The Unit of Work Implementor&lt;/h3&gt;
&lt;p&gt;This class defines an actual Unit of Work instance. It implements the already 
mentioned (and defined) interface IUnitOfWork which in turn inherits from 
IDisposal. This allows us to work with a UoW using the following syntax&lt;/p&gt;
&lt;div&gt;
&lt;div style="border-style:none;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;&lt;span style="color:#0000ff;"&gt;using&lt;/span&gt;(UnitOfWork.Start())&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;{&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;    &lt;span style="color:#008000;"&gt;// use Unit of Work&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;}&lt;/pre&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;at the end of the block the Dispose method of the UoW will be called. So 
let&amp;#39;s first think of a test for the implementation of this method. Here we have 
to use mocking to be able to test our SUT (system under test) in isolation. So 
let me setup a test fixture first.&lt;/p&gt;
&lt;div&gt;
&lt;div style="border-style:none;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;[TestFixture]&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;&lt;span style="color:#0000ff;"&gt;public&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;class&lt;/span&gt; UnitOfWorkImplementor_Fixture&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;{&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;    &lt;span style="color:#0000ff;"&gt;private&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;readonly&lt;/span&gt; MockRepository _mocks = &lt;span style="color:#0000ff;"&gt;new&lt;/span&gt; MockRepository();&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;    &lt;span style="color:#0000ff;"&gt;private&lt;/span&gt; IUnitOfWorkFactory _factory;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;    &lt;span style="color:#0000ff;"&gt;private&lt;/span&gt; ISession _session;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;    &lt;span style="color:#0000ff;"&gt;private&lt;/span&gt; IUnitOfWorkImplementor _uow;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;&amp;nbsp;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;    [SetUp]&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;    &lt;span style="color:#0000ff;"&gt;public&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;void&lt;/span&gt; SetupContext()&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;    {&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;        _factory = _mocks.DynamicMock&amp;lt;IUnitOfWorkFactory&amp;gt;();&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;        _session = _mocks.DynamicMock&amp;lt;ISession&amp;gt;();&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;    }&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;}&lt;/pre&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;Again I use &lt;a href="http://www.ayende.com/projects/rhino-mocks.aspx"&gt;Rhino.Mocks&lt;/a&gt; as my 
mocking framework. My UoW instance has two external dependencies namely the 
UnitOfWork factory and the NHibernate session. In the SetupContext I generate a 
dynamic mock for each of them.&lt;/p&gt;
&lt;p&gt;Now I&amp;nbsp; can write my test method&lt;/p&gt;
&lt;div&gt;
&lt;div style="border-style:none;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;[Test]&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;&lt;span style="color:#0000ff;"&gt;public&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;void&lt;/span&gt; Can_Dispose_UnitOfWorkImplementor()&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;{&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;    &lt;span style="color:#0000ff;"&gt;using&lt;/span&gt;(_mocks.Record())&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;    {&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;        Expect.Call(() =&amp;gt; _factory.DisposeUnitOfWork(&lt;span style="color:#0000ff;"&gt;null&lt;/span&gt;)).IgnoreArguments();&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;        Expect.Call(_session.Dispose);&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;    }&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;    &lt;span style="color:#0000ff;"&gt;using&lt;/span&gt; (_mocks.Playback())&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;    {&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;        _uow = &lt;span style="color:#0000ff;"&gt;new&lt;/span&gt; UnitOfWorkImplementor(_factory, _session);&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;        _uow.Dispose();&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;    }&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;}&lt;/pre&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;During the recording phase I define my expectations (of what should happen 
when calling the &lt;b&gt;Dispose&lt;/b&gt; method of the UoW). First the 
&lt;b&gt;DisposeUnitOfWork&lt;/b&gt; method of the factory and second the 
&lt;b&gt;Dispose&lt;/b&gt; method of the session object should be called.&lt;/p&gt;
&lt;p&gt;Here is the code which fulfills this test&lt;/p&gt;
&lt;div&gt;
&lt;div style="border-style:none;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;&lt;span style="color:#0000ff;"&gt;public&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;void&lt;/span&gt; Dispose()&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;{&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;    _factory.DisposeUnitOfWork(&lt;span style="color:#0000ff;"&gt;this&lt;/span&gt;);&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;    _session.Dispose();&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;}&lt;/pre&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;As you can see I just forward the call to the Unit of Work factory and 
dispose my internal (NHibernate) session instance as formulated in the 
expectations of the test.&lt;/p&gt;
&lt;p&gt;When working with a UoW I also have to be able to use transactions. Thus I 
need a way to &amp;quot;play&amp;quot; with transactions. Let&amp;#39;s call the corresponding methods 
&lt;b&gt;BeginTransaction&lt;/b&gt; and &lt;b&gt;TransactionalFlush&lt;/b&gt;.&lt;/p&gt;
&lt;h3&gt;Generic Transaction&lt;/h3&gt;
&lt;p&gt;To shield the client code from all NHibernate specifics and to provide a 
simple(r) interface I define a &lt;b&gt;GenericTransaction&lt;/b&gt; class (which 
implements the interface &lt;b&gt;IGenericTransaction&lt;/b&gt;) which is just a 
wrapper around the NHibernate transaction. &lt;/p&gt;
&lt;p&gt;I think that the implementation is trivial and doesn&amp;#39;t need any further 
explanation&lt;/p&gt;
&lt;div&gt;
&lt;div style="border-style:none;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;&lt;span style="color:#0000ff;"&gt;public&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;interface&lt;/span&gt; IGenericTransaction : IDisposable&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;{&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;    &lt;span style="color:#0000ff;"&gt;void&lt;/span&gt; Commit();&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;    &lt;span style="color:#0000ff;"&gt;void&lt;/span&gt; Rollback();&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;}&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;&amp;nbsp;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;&lt;span style="color:#0000ff;"&gt;public&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;class&lt;/span&gt; GenericTransaction : IGenericTransaction&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;{&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;    &lt;span style="color:#0000ff;"&gt;private&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;readonly&lt;/span&gt; ITransaction _transaction;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;&amp;nbsp;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;    &lt;span style="color:#0000ff;"&gt;public&lt;/span&gt; GenericTransaction(ITransaction transaction)&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;    {&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;        _transaction = transaction;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;    }&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;&amp;nbsp;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;    &lt;span style="color:#0000ff;"&gt;public&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;void&lt;/span&gt; Commit()&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;    {&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;        _transaction.Commit();&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;    }&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;&amp;nbsp;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;    &lt;span style="color:#0000ff;"&gt;public&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;void&lt;/span&gt; Rollback()&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;    {&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;        _transaction.Rollback();&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;    }&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;&amp;nbsp;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;    &lt;span style="color:#0000ff;"&gt;public&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;void&lt;/span&gt; Dispose()&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;    {&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;        _transaction.Dispose();&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;    }&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;}&lt;/pre&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;just note that the &lt;b&gt;IGenericTransaction&lt;/b&gt; inherits form 
&lt;b&gt;IDisposable&lt;/b&gt;.&lt;/p&gt;
&lt;p&gt;With this definition of a generic transaction we can proceed to the 
implementation of the &lt;b&gt;BeginTransaction&lt;/b&gt; and 
&lt;b&gt;TransactionalFlush&lt;/b&gt; methods. &lt;/p&gt;
&lt;p&gt;First I&amp;#39;ll implement the BeginTransaction method. As usual I define the test 
first&lt;/p&gt;
&lt;div&gt;
&lt;div style="border-style:none;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;[Test]&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;&lt;span style="color:#0000ff;"&gt;public&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;void&lt;/span&gt; Can_BeginTransaction()&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;{&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;    &lt;span style="color:#0000ff;"&gt;using&lt;/span&gt;(_mocks.Record())&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;    {&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;        Expect.Call(_session.BeginTransaction()).Return(&lt;span style="color:#0000ff;"&gt;null&lt;/span&gt;);&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;    }&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;    &lt;span style="color:#0000ff;"&gt;using&lt;/span&gt; (_mocks.Playback())&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;    {&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;        _uow = &lt;span style="color:#0000ff;"&gt;new&lt;/span&gt; UnitOfWorkImplementor(_factory, _session);&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;        var transaction = _uow.BeginTransaction();&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;        Assert.IsNotNull(transaction);&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;    }&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;}&lt;/pre&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;I expect that during execution of the method under test the BeginTransaction 
method of the NHibernate session is called. After calling 
&lt;b&gt;BeginTransaction&lt;/b&gt; on the UoW (in the Playback phase) I 
additionally test whether I get a not-null transaction.&lt;/p&gt;
&lt;p&gt;I also want to be able to start a transaction and define an &lt;a href="http://www.hibernate.org/hib_docs/nhibernate/html/transactions.html"&gt;isolation 
level for the transaction&lt;/a&gt;. The corresponding test might look like&lt;/p&gt;
&lt;div&gt;
&lt;div style="border-style:none;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;[Test]&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;&lt;span style="color:#0000ff;"&gt;public&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;void&lt;/span&gt; Can_BeginTransaction_specifying_isolation_level()&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;{&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;    var isolationLevel = IsolationLevel.Serializable;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;    &lt;span style="color:#0000ff;"&gt;using&lt;/span&gt;(_mocks.Record())&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;    {   &lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;        Expect.Call(_session.BeginTransaction(isolationLevel)).Return(&lt;span style="color:#0000ff;"&gt;null&lt;/span&gt;);&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;    }&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;    &lt;span style="color:#0000ff;"&gt;using&lt;/span&gt; (_mocks.Playback())&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;    {&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;        _uow = &lt;span style="color:#0000ff;"&gt;new&lt;/span&gt; UnitOfWorkImplementor(_factory, _session);&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;        var transaction = _uow.BeginTransaction(isolationLevel);&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;        Assert.IsNotNull(transaction);&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;    }&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;}&lt;/pre&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;To fulfill the test(s) I just have to create a new instance of a generic 
transaction and pass the result of the &lt;i&gt;_session.BeginTransaction&lt;/i&gt; call 
to the constructor (that is: a NHibernate ITransaction object)&lt;/p&gt;
&lt;div&gt;
&lt;div style="border-style:none;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;&lt;span style="color:#0000ff;"&gt;public&lt;/span&gt; IGenericTransaction BeginTransaction()&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;{&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;    &lt;span style="color:#0000ff;"&gt;return&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;new&lt;/span&gt; GenericTransaction(_session.BeginTransaction());&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;}&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;&amp;nbsp;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;&lt;span style="color:#0000ff;"&gt;public&lt;/span&gt; IGenericTransaction BeginTransaction(IsolationLevel isolationLevel)&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;{&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;    &lt;span style="color:#0000ff;"&gt;return&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;new&lt;/span&gt; GenericTransaction(_session.BeginTransaction(isolationLevel));&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;}&lt;/pre&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;The methods each return me an instance of type GenericTransaction which I can 
use in my code and call their respective commit or rollback methods if 
appropriate.&lt;/p&gt;
&lt;p&gt;The &lt;b&gt;TransactionalFlush&lt;/b&gt; method should flush the content of 
the NHibernate session to the database wrapped inside a transaction. Let&amp;#39;s 
define the test(s) for it&lt;/p&gt;
&lt;div&gt;
&lt;div style="border-style:none;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;[Test]&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;&lt;span style="color:#0000ff;"&gt;public&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;void&lt;/span&gt; Can_execute_TransactionalFlush()&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;{&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;    var tx = _mocks.CreateMock&amp;lt;ITransaction&amp;gt;();&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;    var session = _mocks.DynamicMock&amp;lt;ISession&amp;gt;();&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;    SetupResult.For(session.BeginTransaction(IsolationLevel.ReadCommitted)).Return(tx);&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;&amp;nbsp;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;    _uow = _mocks.PartialMock&amp;lt;UnitOfWorkImplementor&amp;gt;(_factory, _session);&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;&amp;nbsp;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;    &lt;span style="color:#0000ff;"&gt;using&lt;/span&gt; (_mocks.Record())&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;    {&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;        Expect.Call(tx.Commit);&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;        Expect.Call(tx.Dispose);&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;    }&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;    &lt;span style="color:#0000ff;"&gt;using&lt;/span&gt; (_mocks.Playback())&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;    {&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;        _uow = &lt;span style="color:#0000ff;"&gt;new&lt;/span&gt; UnitOfWorkImplementor(_factory, session);&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;        _uow.TransactionalFlush();&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;    }&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;}&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;&amp;nbsp;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;[Test]&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;&lt;span style="color:#0000ff;"&gt;public&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;void&lt;/span&gt; Can_execute_TransactionalFlush_specifying_isolation_level()&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;{&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;    var tx = _mocks.CreateMock&amp;lt;ITransaction&amp;gt;();&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;    var session = _mocks.DynamicMock&amp;lt;ISession&amp;gt;();&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;    SetupResult.For(session.BeginTransaction(IsolationLevel.Serializable)).Return(tx);&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;&amp;nbsp;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;    _uow = _mocks.PartialMock&amp;lt;UnitOfWorkImplementor&amp;gt;(_factory, session);&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;&amp;nbsp;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;    &lt;span style="color:#0000ff;"&gt;using&lt;/span&gt; (_mocks.Record())&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;    {&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;        Expect.Call(tx.Commit);&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;        Expect.Call(tx.Dispose);&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;    }&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;    &lt;span style="color:#0000ff;"&gt;using&lt;/span&gt; (_mocks.Playback())&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;    {&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;        _uow.TransactionalFlush(IsolationLevel.Serializable);&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;    }&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;}&lt;/pre&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;and the implementation is straight forward&lt;/p&gt;
&lt;div&gt;
&lt;div style="border-style:none;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;&lt;span style="color:#0000ff;"&gt;public&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;void&lt;/span&gt; TransactionalFlush()&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;{&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;    TransactionalFlush(IsolationLevel.ReadCommitted);&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;}&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;&amp;nbsp;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;&lt;span style="color:#0000ff;"&gt;public&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;void&lt;/span&gt; TransactionalFlush(IsolationLevel isolationLevel)&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;{&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;    IGenericTransaction tx = BeginTransaction(isolationLevel);&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;    &lt;span style="color:#0000ff;"&gt;try&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;    {&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;        &lt;span style="color:#008000;"&gt;//forces a flush of the current unit of work&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;        tx.Commit();&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;    }&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;    &lt;span style="color:#0000ff;"&gt;catch&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;    {&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;        tx.Rollback();&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;        &lt;span style="color:#0000ff;"&gt;throw&lt;/span&gt;;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;    }&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;    &lt;span style="color:#0000ff;"&gt;finally&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;    {&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;        tx.Dispose();&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;    }&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;}&lt;/pre&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;Note that when you don&amp;#39;t provide an explicit transaction isolation level our 
implementation automatically assumes an isolation level equal to &amp;quot;read 
commited&amp;quot;. Note also that if the Commit of the transaction fails the transaction 
is rolled back.&lt;/p&gt;
&lt;p&gt;&lt;b&gt;Important&lt;/b&gt;: In the case of an exception during 
&lt;b&gt;TransactionalFlush&lt;/b&gt; do not try to reuse the current unit of work 
since the session is in an &lt;a href="http://www.hibernate.org/42.html#A3"&gt;inconsistent state&lt;/a&gt; and must be 
closed. Thus abandon this UoW and start a new one.&lt;/p&gt;
&lt;p&gt;To increase the usability of the UoW instance a little bit I add the 
following members (which need no further explanation)&lt;/p&gt;
&lt;div&gt;
&lt;div style="border-style:none;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;&lt;span style="color:#0000ff;"&gt;public&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;bool&lt;/span&gt; IsInActiveTransaction&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;{&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;    get&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;    {&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;        &lt;span style="color:#0000ff;"&gt;return&lt;/span&gt; _session.Transaction.IsActive;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;    }&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;}&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;&amp;nbsp;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;&lt;span style="color:#0000ff;"&gt;public&lt;/span&gt; IUnitOfWorkFactory Factory&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;{&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;    get { &lt;span style="color:#0000ff;"&gt;return&lt;/span&gt; _factory; }&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;}&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;&amp;nbsp;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;&lt;span style="color:#0000ff;"&gt;public&lt;/span&gt; ISession Session&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;{&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;    get { &lt;span style="color:#0000ff;"&gt;return&lt;/span&gt; _session; }&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;}&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;&amp;nbsp;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;&lt;span style="color:#0000ff;"&gt;public&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;void&lt;/span&gt; Flush()&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;{&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;    _session.Flush();&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;}&lt;/pre&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;That&amp;#39;s it! We have now a simple implementation of the Unit of Work pattern 
for NHibernate. Let me provide an overall picture of our implementation&lt;/p&gt;
&lt;p&gt;&lt;img src="/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/nhibernate.UoW/UoW-overview.png" alt="" /&gt;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;Please remember&lt;/b&gt;: In this current version the UoW is strictly 
NOT thread-safe! But I&amp;#39;ll show you how to make it thread-safe in the next post.&amp;nbsp; 
&lt;/p&gt;
&lt;h2&gt;Using the Unit of Work&lt;/h2&gt;
&lt;p&gt;In the following section I&amp;#39;ll quickly show the typical usage of the UoW. As 
usual I do this via TDD. I want to demonstrate how one can define a new instance 
of an entity and add it to the database. In this case the entity is a simple 
Person type object.&lt;/p&gt;
&lt;p&gt;Let us first set up a test fixture as follows&lt;/p&gt;
&lt;div&gt;
&lt;div style="border-style:none;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;&lt;span style="color:#0000ff;"&gt;using&lt;/span&gt; System;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;&lt;span style="color:#0000ff;"&gt;using&lt;/span&gt; System.Reflection;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;&lt;span style="color:#0000ff;"&gt;using&lt;/span&gt; NHibernate.Tool.hbm2ddl;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;&lt;span style="color:#0000ff;"&gt;using&lt;/span&gt; NUnit.Framework;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;&amp;nbsp;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;&lt;span style="color:#0000ff;"&gt;namespace&lt;/span&gt; NHibernateUnitOfWork.Tests&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;{&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;    [TestFixture]&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;    &lt;span style="color:#0000ff;"&gt;public&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;class&lt;/span&gt; Test_usage_of_UnitOfWork&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;    {&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;        [SetUp]&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;        &lt;span style="color:#0000ff;"&gt;public&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;void&lt;/span&gt; SetupContext()&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;        {&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;            UnitOfWork.Configuration.AddAssembly(Assembly.GetExecutingAssembly());&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;            &lt;span style="color:#0000ff;"&gt;new&lt;/span&gt; SchemaExport(UnitOfWork.Configuration).Execute(&lt;span style="color:#0000ff;"&gt;false&lt;/span&gt;, &lt;span style="color:#0000ff;"&gt;true&lt;/span&gt;, &lt;span style="color:#0000ff;"&gt;false&lt;/span&gt;, &lt;span style="color:#0000ff;"&gt;false&lt;/span&gt;);&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;        }&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;    }&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;}&lt;/pre&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;In the &lt;b&gt;SetupContext&lt;/b&gt; method I first add the current assembly 
(the one in which this test is running) as a source of the &lt;i&gt;schema mapping 
information&lt;/i&gt; to the configuration of NHibernate (which I can access via our 
&lt;b&gt;UnitOfWork&lt;/b&gt; class). It is important that this call is done prior 
to the creation of the &lt;b&gt;SessionFactory&lt;/b&gt; (that is prior to using a 
session).&lt;/p&gt;
&lt;p&gt;After extending the configuration I use the &lt;b&gt;SchemaExport&lt;/b&gt; 
class of NHibernate to automatically generate the database schema for me.&lt;/p&gt;
&lt;p&gt;But wait: up to now I have not defined any schema at all! So let&amp;#39;s do it now. 
Let&amp;#39;s define a simple &lt;b&gt;Person&lt;/b&gt; entity. Add a new file 
&lt;b&gt;Person.cs&lt;/b&gt; to the test project and add the following code&lt;/p&gt;
&lt;div&gt;
&lt;div style="border-style:none;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;&lt;span style="color:#0000ff;"&gt;public&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;class&lt;/span&gt; Person&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;{&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;    &lt;span style="color:#0000ff;"&gt;public&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;virtual&lt;/span&gt; Guid Id { get; set; }&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;    &lt;span style="color:#0000ff;"&gt;public&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;virtual&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;string&lt;/span&gt; Name { get; set; }&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;    &lt;span style="color:#0000ff;"&gt;public&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;virtual&lt;/span&gt; DateTime Birthdate { get; set; }&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;}&lt;/pre&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;add an XML mapping document called &lt;b&gt;Person.hbm.xml&lt;/b&gt; to the 
test project and define the following content&lt;/p&gt;
&lt;div&gt;
&lt;div style="border-style:none;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;&lt;span style="color:#0000ff;"&gt;&amp;lt;?&lt;/span&gt;&lt;span style="color:#800000;"&gt;xml&lt;/span&gt; &lt;span style="color:#ff0000;"&gt;version&lt;/span&gt;&lt;span style="color:#0000ff;"&gt;=&amp;quot;1.0&amp;quot;&lt;/span&gt; &lt;span style="color:#ff0000;"&gt;encoding&lt;/span&gt;&lt;span style="color:#0000ff;"&gt;=&amp;quot;utf-8&amp;quot;&lt;/span&gt; ?&lt;span style="color:#0000ff;"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;&lt;span style="color:#0000ff;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color:#800000;"&gt;hibernate-mapping&lt;/span&gt; &lt;span style="color:#ff0000;"&gt;xmlns&lt;/span&gt;&lt;span style="color:#0000ff;"&gt;=&amp;quot;urn:nhibernate-mapping-2.2&amp;quot;&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;                   &lt;span style="color:#ff0000;"&gt;assembly&lt;/span&gt;&lt;span style="color:#0000ff;"&gt;=&amp;quot;NHibernateUnitOfWork.Tests&amp;quot;&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;                   &lt;span style="color:#ff0000;"&gt;namespace&lt;/span&gt;&lt;span style="color:#0000ff;"&gt;=&amp;quot;NHibernateUnitOfWork.Tests&amp;quot;&lt;/span&gt;&lt;span style="color:#0000ff;"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;&amp;nbsp;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;  &lt;span style="color:#0000ff;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color:#800000;"&gt;class&lt;/span&gt; &lt;span style="color:#ff0000;"&gt;name&lt;/span&gt;&lt;span style="color:#0000ff;"&gt;=&amp;quot;Person&amp;quot;&lt;/span&gt;&lt;span style="color:#0000ff;"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;    &lt;span style="color:#0000ff;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color:#800000;"&gt;id&lt;/span&gt; &lt;span style="color:#ff0000;"&gt;name&lt;/span&gt;&lt;span style="color:#0000ff;"&gt;=&amp;quot;Id&amp;quot;&lt;/span&gt;&lt;span style="color:#0000ff;"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;      &lt;span style="color:#0000ff;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color:#800000;"&gt;generator&lt;/span&gt; &lt;span style="color:#ff0000;"&gt;class&lt;/span&gt;&lt;span style="color:#0000ff;"&gt;=&amp;quot;guid&amp;quot;&lt;/span&gt;&lt;span style="color:#0000ff;"&gt;/&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;    &lt;span style="color:#0000ff;"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color:#800000;"&gt;id&lt;/span&gt;&lt;span style="color:#0000ff;"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;    &lt;span style="color:#0000ff;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color:#800000;"&gt;property&lt;/span&gt; &lt;span style="color:#ff0000;"&gt;name&lt;/span&gt;&lt;span style="color:#0000ff;"&gt;=&amp;quot;Name&amp;quot;&lt;/span&gt; &lt;span style="color:#ff0000;"&gt;not-null&lt;/span&gt;&lt;span style="color:#0000ff;"&gt;=&amp;quot;true&amp;quot;&lt;/span&gt; &lt;span style="color:#ff0000;"&gt;length&lt;/span&gt;&lt;span style="color:#0000ff;"&gt;=&amp;quot;50&amp;quot;&lt;/span&gt;&lt;span style="color:#0000ff;"&gt;/&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;    &lt;span style="color:#0000ff;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color:#800000;"&gt;property&lt;/span&gt; &lt;span style="color:#ff0000;"&gt;name&lt;/span&gt;&lt;span style="color:#0000ff;"&gt;=&amp;quot;Birthdate&amp;quot;&lt;/span&gt; &lt;span style="color:#ff0000;"&gt;not-null&lt;/span&gt;&lt;span style="color:#0000ff;"&gt;=&amp;quot;true&amp;quot;&lt;/span&gt;&lt;span style="color:#0000ff;"&gt;/&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;  &lt;span style="color:#0000ff;"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color:#800000;"&gt;class&lt;/span&gt;&lt;span style="color:#0000ff;"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;&lt;span style="color:#0000ff;"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color:#800000;"&gt;hibernate-mapping&lt;/span&gt;&lt;span style="color:#0000ff;"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;Don&amp;#39;t forget to set the &amp;#39;Build Action&amp;#39; property of this item to 
&lt;b&gt;&amp;#39;Embedded Resource&amp;#39;&lt;/b&gt;!&lt;/p&gt;
&lt;p&gt;Now we can write a test to insert a new person instance into the 
database.&lt;/p&gt;
&lt;div&gt;
&lt;div style="border-style:none;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;[Test]&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;&lt;span style="color:#0000ff;"&gt;public&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;void&lt;/span&gt; Can_add_a_new_instance_of_an_entity_to_the_database()&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;{&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;    &lt;span style="color:#0000ff;"&gt;using&lt;/span&gt;(UnitOfWork.Start())&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;    {&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;        var person = &lt;span style="color:#0000ff;"&gt;new&lt;/span&gt; Person {Name = &lt;span style="color:#006080;"&gt;&amp;quot;John Doe&amp;quot;&lt;/span&gt;, Birthdate = &lt;span style="color:#0000ff;"&gt;new&lt;/span&gt; DateTime(1915, 12, 15)};&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;        UnitOfWork.CurrentSession.Save(person);&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;        UnitOfWork.Current.TransactionalFlush();&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;    }&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;}&lt;/pre&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;When running this test the output generated by NHibernate looks similar to 
this&lt;/p&gt;
&lt;div&gt;
&lt;div style="border-style:none;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;NHibernate: INSERT &lt;span style="color:#0000ff;"&gt;INTO&lt;/span&gt; Person (Name, Birthdate, Id) &lt;span style="color:#0000ff;"&gt;VALUES&lt;/span&gt; (@p0, @p1, @p2); &lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;@p0 = &lt;span style="color:#006080;"&gt;&amp;#39;John Doe&amp;#39;&lt;/span&gt;, @p1 = &lt;span style="color:#006080;"&gt;&amp;#39;15.12.1915 00:00:00&amp;#39;&lt;/span&gt;, &lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;@p2 = &lt;span style="color:#006080;"&gt;&amp;#39;bb72ae4c-7d64-4c16-84dc-c0ba2c7d306b&amp;#39;&lt;/span&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;h2&gt;Summary&lt;/h2&gt;
&lt;p&gt;I have shown you a possible implementation of the &lt;b&gt;Unit of 
Work&lt;/b&gt; pattern for NHibernate. The implementation has been developed by 
using &lt;a href="http://en.wikipedia.org/wiki/Test-driven_development"&gt;TDD&lt;/a&gt;. 
The usage of a Unit of Work pattern simplifies the data manipulation tasks and 
hides the infrastructure details from the consumer of the UoW. NHibernate offers 
it&amp;#39;s own implementation of the UoW in the form of the Session object. But 
NHibernate is just one of several possible ORM tools. With this implementation 
of the UoW pattern we have hidden most of the specifics of NHibernate an provide 
a generic interface to the consumer of the UoW.&lt;/p&gt;
&lt;p&gt;There are just two open points &lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;our implementation in &lt;b&gt;not&lt;/b&gt; thread safe 
&lt;/li&gt;
&lt;li&gt;we still need to access the session object (through 
UnitOfWork.CurrentSession) to read or modify our entites &lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;The former I&amp;#39;ll cover in the third part of this article and the latter problem can be solved by 
introducing a (generic) repository.&lt;/p&gt;
&lt;h1&gt;Part 3&lt;/h1&gt;
&lt;h2&gt;Introduction&lt;/h2&gt;
&lt;p&gt;In the previous two chapters&lt;a href="http://blogs.hibernatingrhinos.com/nhibernate/archive/2008/04/13/nhibernate-and-the-unit-of-work-pattern-part-2.aspx"&gt;&lt;/a&gt; 
I introduced the Unit of Work pattern and developed a working version based on 
NHibernate. One weak point of the shown implementation is that it is strictly 
&lt;i&gt;non thread safe&lt;/i&gt;. In NHibernate the &lt;b&gt;session object&lt;/b&gt; 
takes the role of the Unit of Work container. The session object is not thread 
safe! That is a session instance may not be accessed from different threads. If 
your application is running on multiple threads (typically an application 
running on the server) then you have to open a new session instance for each 
running thread. &lt;/p&gt;
&lt;p&gt;In this post I want to improve the implementation of the Unit of Work pattern 
such as that it is thread safe. The class which starts a new unit of work is a 
static class. All static members of this class are accessible from each thread 
of the application domain in which your application is running. Now fortunately 
.NET provides us a mean to define pseudo static fields in a type which are local 
to a single thread. That is this state is not shared between different threads. 
Each thread has its own thread static state. To make a field thread static one 
has to decorate it with the [&lt;b&gt;ThreadStatic&lt;/b&gt;] attribute. &lt;/p&gt;
&lt;p&gt;The easiest and most pragmatic approach would now be to just decorate our 
_&lt;b&gt;innerUnitOfWork&lt;/b&gt; field of the &lt;b&gt;UnitOfWork &lt;/b&gt;class 
with the [ThreadStatic] attribute. But eventually we want to keep additional 
state in our Unit of Work. Thus we implement a special &lt;b&gt;Data&lt;/b&gt; 
class which is a kind of a wrapper around a Hashtable. &lt;/p&gt;
&lt;h2&gt;Container for Thread Static State&lt;/h2&gt;
&lt;p&gt;There are 2 possible scenarios I want to discuss. You either develop an 
application with a web client or an application with a windows client (e.g. 
WinForms). &lt;/p&gt;
&lt;p&gt;In a web application one has the so called &lt;b&gt;Http context&lt;/b&gt; for 
each request. Multiple requests from different clients can run at the same but 
each of them runs on a different thread and has it&amp;#39;s own context. In this 
situation we store the data relevant to the unit of work in the context of the 
request.&lt;/p&gt;
&lt;p&gt;In a windows client application (i.e. Smart Client Application) on the other 
hand we have a single client that might run on different threads at the same 
time. In this situation we &amp;quot;attach&amp;quot; the data relevant to the unit of work in so 
called thread-static fields. A thread-static field is not shared between 
different threads in the same application. To make a (static) field 
thread-static we have to just decorate it with a [&lt;b&gt;ThreadStatic&lt;/b&gt;] 
attribute.&lt;/p&gt;
&lt;p&gt;In our Unit of Work implementation we have the static UnitOfWork class which 
contains a static field _&lt;b&gt;innerUnitOfWork&lt;/b&gt; of type 
&lt;b&gt;IUnitOfWork&lt;/b&gt;. We now need to change &lt;i&gt;this&lt;/i&gt; since this 
kind of implementation is not thread safe. Since we might want to save other 
data in a thread safe way as well (not just the current instance of the unit of 
work) we choose a slightly more sophisticated solution.&lt;/p&gt;
&lt;p&gt;Let&amp;#39;s define a static class &lt;b&gt;Local&lt;/b&gt; which encapsulates the 
details whether we run a web- or a win-application. This class has just one 
(static) read-only property Data of type &lt;b&gt;ILocalData&lt;/b&gt;.&lt;/p&gt;
&lt;div&gt;
&lt;div style="border-style:none;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;&lt;span style="color:#0000ff;"&gt;using&lt;/span&gt; System;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;&lt;span style="color:#0000ff;"&gt;using&lt;/span&gt; System.Collections;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;&amp;nbsp;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;&lt;span style="color:#0000ff;"&gt;namespace&lt;/span&gt; NHibernateUnitOfWork&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;{&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;    &lt;span style="color:#0000ff;"&gt;public&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;static&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;class&lt;/span&gt; Local&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;    {&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;        &lt;span style="color:#0000ff;"&gt;static&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;readonly&lt;/span&gt; ILocalData _data = &lt;span style="color:#0000ff;"&gt;new&lt;/span&gt; LocalData();&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;&amp;nbsp;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;        &lt;span style="color:#0000ff;"&gt;public&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;static&lt;/span&gt; ILocalData Data&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;        {&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;            get { &lt;span style="color:#0000ff;"&gt;return&lt;/span&gt; _data; }&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;        }&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;&amp;nbsp;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;        &lt;span style="color:#0000ff;"&gt;private&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;class&lt;/span&gt; LocalData : ILocalData&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;        {&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;            &lt;span style="color:#008000;"&gt;// implementation details to de defined&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;        }&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;    }&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;}&lt;/pre&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;All details of our implementation are now &amp;quot;hidden&amp;quot; in the class 
&lt;b&gt;LocalData&lt;/b&gt; which we choose to be a private child class of the 
&lt;b&gt;Local&lt;/b&gt; class. We now want to be able to save into and read data 
from this local container via a key, e.g.&lt;/p&gt;
&lt;div&gt;
&lt;div style="border-style:none;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;Local.Data[&lt;span style="color:#006080;"&gt;&amp;quot;some key&amp;quot;&lt;/span&gt;] = someValue;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;&lt;span style="color:#008000;"&gt;// or&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;otherValue = Local.Data[&lt;span style="color:#006080;"&gt;&amp;quot;other key&amp;quot;&lt;/span&gt;];&lt;/pre&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;This should be in a thread safe way. Obviously the above sample client code 
implies that we use some kind of &lt;i&gt;dictionary&lt;/i&gt; to internally store our 
data.&lt;/p&gt;
&lt;p&gt;As usual we formulate our intention in a unit test which might look like 
this&lt;/p&gt;
&lt;div&gt;
&lt;div style="border-style:none;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;&lt;span style="color:#0000ff;"&gt;using&lt;/span&gt; System;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;&lt;span style="color:#0000ff;"&gt;using&lt;/span&gt; NUnit.Framework;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;&amp;nbsp;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;&lt;span style="color:#0000ff;"&gt;namespace&lt;/span&gt; NHibernateUnitOfWork.Tests&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;{&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;    [TestFixture]&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;    &lt;span style="color:#0000ff;"&gt;public&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;class&lt;/span&gt; LocalData_Fixture&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;    {&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;        [Test]&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;        &lt;span style="color:#0000ff;"&gt;public&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;void&lt;/span&gt; Can_store_values_in_local_data()&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;        {&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;            Local.Data[&lt;span style="color:#006080;"&gt;&amp;quot;one&amp;quot;&lt;/span&gt;] = &lt;span style="color:#006080;"&gt;&amp;quot;This is a string&amp;quot;&lt;/span&gt;;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;            Local.Data[&lt;span style="color:#006080;"&gt;&amp;quot;two&amp;quot;&lt;/span&gt;] = 99.9m;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;            var person = &lt;span style="color:#0000ff;"&gt;new&lt;/span&gt; Person {Name = &lt;span style="color:#006080;"&gt;&amp;quot;John Doe&amp;quot;&lt;/span&gt;, Birthdate = &lt;span style="color:#0000ff;"&gt;new&lt;/span&gt; DateTime(1991, 1, 15)};&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;            Local.Data[1] = person;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;&amp;nbsp;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;            Assert.AreEqual(3, Local.Data.Count);&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;            Assert.AreEqual(&lt;span style="color:#006080;"&gt;&amp;quot;This is a string&amp;quot;&lt;/span&gt;, Local.Data[&lt;span style="color:#006080;"&gt;&amp;quot;one&amp;quot;&lt;/span&gt;]);&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;            Assert.AreEqual(99.9m, Local.Data[&lt;span style="color:#006080;"&gt;&amp;quot;two&amp;quot;&lt;/span&gt;]);&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;            Assert.AreSame(person, Local.Data[1]);&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;        }&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;    }&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;}&lt;/pre&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;The test shows that I want to be able to not only store basic types but any 
complex type in my local data container. In this case a string, an integer and 
an instance of a Person class. The Person class is very basic at looks like 
follows&lt;/p&gt;
&lt;div&gt;
&lt;div style="border-style:none;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;&lt;span style="color:#0000ff;"&gt;public&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;class&lt;/span&gt; Person&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;{&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;    &lt;span style="color:#0000ff;"&gt;public&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;virtual&lt;/span&gt; Guid Id { get; set; }&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;    &lt;span style="color:#0000ff;"&gt;public&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;virtual&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;string&lt;/span&gt; Name { get; set; }&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;    &lt;span style="color:#0000ff;"&gt;public&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;virtual&lt;/span&gt; DateTime Birthdate { get; set; }&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;}&lt;/pre&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;Please also note that I use keys of different type (&lt;i&gt;string&lt;/i&gt; and 
&lt;i&gt;int&lt;/i&gt;). &lt;/p&gt;
&lt;h3&gt;Implementation for Smart Client Applications&lt;/h3&gt;
&lt;p&gt;Let&amp;#39;s first assume that we want to provide a thread safe unit of work 
implementation for the smart client application. Then the most basic 
implementation to fulfill&amp;nbsp; this test is&lt;/p&gt;
&lt;div&gt;
&lt;div style="border-style:none;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;&lt;span style="color:#0000ff;"&gt;private&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;class&lt;/span&gt; LocalData : ILocalData&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;{&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;    &lt;span style="color:#0000ff;"&gt;private&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;static&lt;/span&gt; Hashtable _localData = new Hashtable();&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;&amp;nbsp;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;    &lt;span style="color:#0000ff;"&gt;public&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;object&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;this&lt;/span&gt;[&lt;span style="color:#0000ff;"&gt;object&lt;/span&gt; key]&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;    {&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;        get { &lt;span style="color:#0000ff;"&gt;return&lt;/span&gt; _localData[key]; }&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;        set { _localData[key] = &lt;span style="color:#0000ff;"&gt;value&lt;/span&gt;; }&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;    }&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;&amp;nbsp;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;    &lt;span style="color:#0000ff;"&gt;public&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;int&lt;/span&gt; Count&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;    {&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;        get { &lt;span style="color:#0000ff;"&gt;return&lt;/span&gt; _localData.Count; }&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;    }&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;}&lt;/pre&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;I just take a hash table as local storage and define an indexer property and 
a Count property (Note: a &lt;i&gt;HashTable&lt;/i&gt; is an often used implementation of 
a &lt;i&gt;Dictionary&lt;/i&gt;).&lt;/p&gt;
&lt;p&gt;We want to also be able to &lt;b&gt;clear&lt;/b&gt; the content of the local 
store and thus we define the following test&lt;/p&gt;
&lt;div&gt;
&lt;div style="border-style:none;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;[Test]&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;&lt;span style="color:#0000ff;"&gt;public&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;void&lt;/span&gt; Can_clear_local_data()&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;{&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;    Local.Data[&lt;span style="color:#006080;"&gt;&amp;quot;one&amp;quot;&lt;/span&gt;] = &lt;span style="color:#006080;"&gt;&amp;quot;This is a string&amp;quot;&lt;/span&gt;;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;    Local.Data[&lt;span style="color:#006080;"&gt;&amp;quot;two&amp;quot;&lt;/span&gt;] = 99.9m;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;    Assert.AreEqual(2, Local.Data.Count);&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;    Local.Data.Clear();&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;    Assert.AreEqual(0, Local.Data.Count);&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;}&lt;/pre&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;The code to fulfill this test is trivial, just add the code snippet below to 
the &lt;b&gt;LocalData&lt;/b&gt; class&lt;/p&gt;
&lt;div&gt;
&lt;div style="border-style:none;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;&lt;span style="color:#0000ff;"&gt;public&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;void&lt;/span&gt; Clear()&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;{&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;    _localData.Clear();&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;}&lt;/pre&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;Unfortunately the test still faults when run! This is because the local data 
storage is static and all test methods access the same container we have a &amp;quot;side 
effect&amp;quot; which we must now compensate. We can do it by just clearing the local 
data container before each test. Add this code to the test fixture class to 
compensate the side effect&lt;/p&gt;
&lt;div&gt;
&lt;div style="border-style:none;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;[SetUp]&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;&lt;span style="color:#0000ff;"&gt;public&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;void&lt;/span&gt; SetupContext()&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;{&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;    Local.Data.Clear();     &lt;span style="color:#008000;"&gt;// start side-effect free!&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;}&lt;/pre&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;Re-run all tests. They should now all pass...&lt;/p&gt;
&lt;p&gt;And now comes the &amp;quot;tricky&amp;quot; part of the implementation where we want to 
guarantee that our local data store is indeed &lt;b&gt;thread safe&lt;/b&gt;. 
Let&amp;#39;s first define a test for this scenario&lt;/p&gt;
&lt;div&gt;
&lt;div style="border-style:none;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;&lt;span style="color:#0000ff;"&gt;private&lt;/span&gt; ManualResetEvent _event;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;&amp;nbsp;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;[Test]&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;&lt;span style="color:#0000ff;"&gt;public&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;void&lt;/span&gt; Local_data_is_thread_local()&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;{&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;    Console.WriteLine(&lt;span style="color:#006080;"&gt;&amp;quot;Starting in main thread {0}&amp;quot;&lt;/span&gt;, Thread.CurrentThread.ManagedThreadId);&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;    Local.Data[&lt;span style="color:#006080;"&gt;&amp;quot;one&amp;quot;&lt;/span&gt;] = &lt;span style="color:#006080;"&gt;&amp;quot;This is a string&amp;quot;&lt;/span&gt;;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;    Assert.AreEqual(1, Local.Data.Count);&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;&amp;nbsp;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;    _event = &lt;span style="color:#0000ff;"&gt;new&lt;/span&gt; ManualResetEvent(&lt;span style="color:#0000ff;"&gt;false&lt;/span&gt;);&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;    var backgroundThread = &lt;span style="color:#0000ff;"&gt;new&lt;/span&gt; Thread(RunInOtherThread);&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;    backgroundThread.Start();&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;&amp;nbsp;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;    &lt;span style="color:#008000;"&gt;// give the background thread some time to do its job&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;    Thread.Sleep(100);&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;    &lt;span style="color:#008000;"&gt;// we still have only one entry (in this thread)&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;    Assert.AreEqual(1, Local.Data.Count);&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;&amp;nbsp;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;    Console.WriteLine(&lt;span style="color:#006080;"&gt;&amp;quot;Signaling background thread from main thread {0}&amp;quot;&lt;/span&gt;, Thread.CurrentThread.ManagedThreadId);&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;    _event.Set();&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;    backgroundThread.Join();&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;}&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;&amp;nbsp;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;&lt;span style="color:#0000ff;"&gt;private&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;void&lt;/span&gt; RunInOtherThread()&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;{&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;    Console.WriteLine(&lt;span style="color:#006080;"&gt;&amp;quot;Starting (background-) thread {0}&amp;quot;&lt;/span&gt;, Thread.CurrentThread.ManagedThreadId);&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;    &lt;span style="color:#008000;"&gt;// initially the local data must be empty for this NEW thread!&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;    Assert.AreEqual(0, Local.Data.Count);&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;    Local.Data[&lt;span style="color:#006080;"&gt;&amp;quot;one&amp;quot;&lt;/span&gt;] = &lt;span style="color:#006080;"&gt;&amp;quot;This is another string&amp;quot;&lt;/span&gt;;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;    Assert.AreEqual(1, Local.Data.Count);&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;&amp;nbsp;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;    Console.WriteLine(&lt;span style="color:#006080;"&gt;&amp;quot;Waiting on (background-) thread {0}&amp;quot;&lt;/span&gt;, Thread.CurrentThread.ManagedThreadId);&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;    _event.WaitOne();&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;    Console.WriteLine(&lt;span style="color:#006080;"&gt;&amp;quot;Ending (background-) thread {0}&amp;quot;&lt;/span&gt;, Thread.CurrentThread.ManagedThreadId);&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;}&lt;/pre&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;In the above code I run two threads in parallel, the thread on which the test 
is running (let&amp;#39;s call it the &lt;b&gt;main thread&lt;/b&gt;) and an additional 
&lt;b&gt;background thread&lt;/b&gt;. The code which is executed in the background 
thread is implemented in the helper method &lt;b&gt;RunInOtherThread&lt;/b&gt;. To 
be able to synchronize the two threads I use an &lt;b&gt;Event&lt;/b&gt;, in this 
case a &lt;b&gt;ManualResetEvent&lt;/b&gt;. I have put some 
&lt;i&gt;Console.WriteLine&lt;/i&gt; statements in the code for debugging purposes.&lt;/p&gt;
&lt;p&gt;In the main thread I add some data to the local data store. Then I spin up 
the background thread. In the background thread I first test that my (thread-) 
local data store is empty and then also fill in some data. With the 
&lt;b&gt;Assert&lt;/b&gt; statements I test that we really have a thread safe 
behavior.&lt;/p&gt;
&lt;p&gt;The only change needed to make my implementation thread safe is to decorate 
the static field _localData with the [ThreadStatic] attribute.&lt;/p&gt;
&lt;div&gt;
&lt;div style="border-style:none;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;[ThreadStatic]&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;&lt;span style="color:#0000ff;"&gt;private&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;static&lt;/span&gt; Hashtable _localData = &lt;span style="color:#0000ff;"&gt;new&lt;/span&gt; Hashtable();&lt;/pre&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;When the test is run it should pass and produce an output similar to this&lt;/p&gt;
&lt;p&gt;&lt;img src="/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/nhibernate.UoW/UoW-Multi_2D00_Threading-UnitTest.png" alt="" /&gt;&lt;/p&gt;
&lt;h3&gt;Implementation for Web&lt;/h3&gt;
&lt;p&gt;As mentioned above in this scenario we want to store our local data in the 
context of the current HTTP request. &lt;/p&gt;
&lt;p&gt;First I want to provide an indicator whether I am running in web and thus I 
add the following to the code snippet to the &lt;b&gt;LocalData&lt;/b&gt; 
class&lt;/p&gt;
&lt;div&gt;
&lt;div style="border-style:none;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;&lt;span style="color:#0000ff;"&gt;public&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;static&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;bool&lt;/span&gt; RunningInWeb&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;{&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;    get { &lt;span style="color:#0000ff;"&gt;return&lt;/span&gt; HttpContext.Current != &lt;span style="color:#0000ff;"&gt;null&lt;/span&gt;; }&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;}&lt;/pre&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;Here I use the &lt;b&gt;HttpContext&lt;/b&gt; class of the .NET framework 
(namespace &lt;i&gt;System.Web&lt;/i&gt;). It&amp;#39;s static property &lt;b&gt;Current&lt;/b&gt; 
is equal to null if we do not run in the context of a web application.&lt;/p&gt;
&lt;p&gt;To abstract the details of the context (web- or smart client application) I 
define a private read-only property &lt;b&gt;LocalHashtable&lt;/b&gt; as below&lt;/p&gt;
&lt;div&gt;
&lt;div style="border-style:none;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;&lt;span style="color:#0000ff;"&gt;private&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;static&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;readonly&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;object&lt;/span&gt; LocalDataHashtableKey = &lt;span style="color:#0000ff;"&gt;new&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;object&lt;/span&gt;();&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;&amp;nbsp;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;&lt;span style="color:#0000ff;"&gt;private&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;static&lt;/span&gt; Hashtable LocalHashtable&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;{&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;    get &lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;    {&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;        &lt;span style="color:#0000ff;"&gt;if&lt;/span&gt; (!RunningInWeb)&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;        {&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;            &lt;span style="color:#0000ff;"&gt;if&lt;/span&gt; (_localData == &lt;span style="color:#0000ff;"&gt;null&lt;/span&gt;)&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;                _localData = &lt;span style="color:#0000ff;"&gt;new&lt;/span&gt; Hashtable();&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;            &lt;span style="color:#0000ff;"&gt;return&lt;/span&gt; _localData;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;        }&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;        &lt;span style="color:#0000ff;"&gt;else&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;        {&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;            var web_hashtable = HttpContext.Current.Items[LocalDataHashtableKey] &lt;span style="color:#0000ff;"&gt;as&lt;/span&gt; Hashtable;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;            &lt;span style="color:#0000ff;"&gt;if&lt;/span&gt; (web_hashtable == &lt;span style="color:#0000ff;"&gt;null&lt;/span&gt;)&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;            {&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;                web_hashtable = &lt;span style="color:#0000ff;"&gt;new&lt;/span&gt; Hashtable();&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;                HttpContext.Current.Items[LocalDataHashtableKey] = web_hashtable;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;            }&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;            &lt;span style="color:#0000ff;"&gt;return&lt;/span&gt; web_hashtable;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;        }&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;    }&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;}&lt;/pre&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;In this code I use the &lt;b&gt;RunningInWeb&lt;/b&gt; helper method to 
distinguish the two cases. In the case of NOT running in web context I test 
whether my thread static _&lt;b&gt;localData&lt;/b&gt; field is equal to null, and 
If so I initialize it with a new instance of type &lt;b&gt;Hashtable&lt;/b&gt;. I 
then return this instance. On the other hand, when running in web context I try 
to access a hash table instance in the &lt;b&gt;Items&lt;/b&gt; collection of the 
current Http context. If I do not find such an instance then I create a new one 
and put it into the items collection of the current context. I then return the 
instance.&lt;/p&gt;
&lt;p&gt;Now I have to locate every place in the &lt;b&gt;LocalData&lt;/b&gt; class 
where I access the _&lt;b&gt;localData&lt;/b&gt; field directly and replace it 
with a reference to the &lt;b&gt;LocalHashtable&lt;/b&gt; property. E.g. the 
indexer will have to be changed as follows&lt;/p&gt;
&lt;div&gt;
&lt;div style="border-style:none;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;&lt;span style="color:#0000ff;"&gt;public&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;object&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;this&lt;/span&gt;[&lt;span style="color:#0000ff;"&gt;object&lt;/span&gt; key]&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;{&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;    get { &lt;span style="color:#0000ff;"&gt;return&lt;/span&gt; LocalHashtable[key]; }&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;    set { LocalHashtable[key] = &lt;span style="color:#0000ff;"&gt;value&lt;/span&gt;; }&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;}&lt;/pre&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;Our thread- and/or Http context local data store is now complete and we can 
use it in our &lt;b&gt;UnitOfWork&lt;/b&gt; class.&lt;/p&gt;
&lt;h2&gt;Make Unit Of Work implementation thread safe&lt;/h2&gt;
&lt;p&gt;To make our unit of work implementation thread safe we change the 
implementation of our static &lt;b&gt;UnitOfWork&lt;/b&gt; class as shown 
below&lt;/p&gt;
&lt;div&gt;
&lt;div style="border-style:none;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;&lt;span style="color:#0000ff;"&gt;public&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;static&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;class&lt;/span&gt; UnitOfWork&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;{&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;    &lt;span style="color:#0000ff;"&gt;private&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;static&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;readonly&lt;/span&gt; IUnitOfWorkFactory _unitOfWorkFactory = &lt;span style="color:#0000ff;"&gt;new&lt;/span&gt; UnitOfWorkFactory();&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;&amp;nbsp;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;    &lt;span style="color:#0000ff;"&gt;public&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;static&lt;/span&gt; Configuration Configuration&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;    {&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;        get { &lt;span style="color:#0000ff;"&gt;return&lt;/span&gt; _unitOfWorkFactory.Configuration; }&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;    }&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;&amp;nbsp;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;    &lt;span style="color:#0000ff;"&gt;public&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;const&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;string&lt;/span&gt; CurrentUnitOfWorkKey = &lt;span style="color:#006080;"&gt;&amp;quot;CurrentUnitOfWork.Key&amp;quot;&lt;/span&gt;;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;&amp;nbsp;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;    &lt;span style="color:#0000ff;"&gt;private&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;static&lt;/span&gt; IUnitOfWork CurrentUnitOfWork&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;    {&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;        get { &lt;span style="color:#0000ff;"&gt;return&lt;/span&gt; Local.Data[CurrentUnitOfWorkKey] &lt;span style="color:#0000ff;"&gt;as&lt;/span&gt; IUnitOfWork; }&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;        set { Local.Data[CurrentUnitOfWorkKey] = &lt;span style="color:#0000ff;"&gt;value&lt;/span&gt;; }&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;    }&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;&amp;nbsp;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;    &lt;span style="color:#0000ff;"&gt;public&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;static&lt;/span&gt; IUnitOfWork Current&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;    {&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;        get&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;        {&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;            var unitOfWork = CurrentUnitOfWork;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;            &lt;span style="color:#0000ff;"&gt;if&lt;/span&gt; (unitOfWork == &lt;span style="color:#0000ff;"&gt;null&lt;/span&gt;)&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;                &lt;span style="color:#0000ff;"&gt;throw&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;new&lt;/span&gt; InvalidOperationException(&lt;span style="color:#006080;"&gt;&amp;quot;You are not in a unit of work&amp;quot;&lt;/span&gt;);&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;            &lt;span style="color:#0000ff;"&gt;return&lt;/span&gt; unitOfWork;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;        }&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;    }&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;&amp;nbsp;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;    &lt;span style="color:#0000ff;"&gt;public&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;static&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;bool&lt;/span&gt; IsStarted&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;    {&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;        get { &lt;span style="color:#0000ff;"&gt;return&lt;/span&gt; CurrentUnitOfWork != &lt;span style="color:#0000ff;"&gt;null&lt;/span&gt;; }&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;    }&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;&amp;nbsp;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;    &lt;span style="color:#0000ff;"&gt;public&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;static&lt;/span&gt; ISession CurrentSession&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;    {&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;        get { &lt;span style="color:#0000ff;"&gt;return&lt;/span&gt; _unitOfWorkFactory.CurrentSession; }&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;        &lt;span style="color:#0000ff;"&gt;internal&lt;/span&gt; set { _unitOfWorkFactory.CurrentSession = &lt;span style="color:#0000ff;"&gt;value&lt;/span&gt;; }&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;    }&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;&amp;nbsp;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;    &lt;span style="color:#0000ff;"&gt;public&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;static&lt;/span&gt; IUnitOfWork Start()&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;    {&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;        &lt;span style="color:#0000ff;"&gt;if&lt;/span&gt; (CurrentUnitOfWork != &lt;span style="color:#0000ff;"&gt;null&lt;/span&gt;)&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;            &lt;span style="color:#0000ff;"&gt;throw&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;new&lt;/span&gt; InvalidOperationException(&lt;span style="color:#006080;"&gt;&amp;quot;You cannot start more than one unit of work at the same time.&amp;quot;&lt;/span&gt;);&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;        &lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;        var unitOfWork = _unitOfWorkFactory.Create();&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;        CurrentUnitOfWork = unitOfWork;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;        &lt;span style="color:#0000ff;"&gt;return&lt;/span&gt; unitOfWork;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;    }&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;&amp;nbsp;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;    &lt;span style="color:#0000ff;"&gt;public&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;static&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;void&lt;/span&gt; DisposeUnitOfWork(IUnitOfWorkImplementor unitOfWork)&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;    {&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;        CurrentUnitOfWork = &lt;span style="color:#0000ff;"&gt;null&lt;/span&gt;;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;    }&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;}&lt;/pre&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;As you can see the field _&lt;b&gt;innerUnitOfWork&lt;/b&gt; has gone and is 
replaced by a private property &lt;b&gt;CurrentUnitOfWork&lt;/b&gt;. This property 
in turn uses the previously defined &lt;b&gt;Local &lt;/b&gt;class to store the 
current unit of work item. &lt;/p&gt;
&lt;p&gt;Note that there is one place in our unit tests that makes a reference to the 
field _&lt;b&gt;innerUnitOfWork&lt;/b&gt; and must thus be changed. It&amp;#39;s the 
method &lt;b&gt;ResetUnitOfWork&lt;/b&gt; in the class 
&lt;b&gt;UnitOfWork_With_Factory_Fixture&lt;/b&gt;. The new implementation is&lt;/p&gt;
&lt;div&gt;
&lt;div style="border-style:none;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;&lt;span style="color:#0000ff;"&gt;private&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;void&lt;/span&gt; ResetUnitOfWork()&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;{&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;    &lt;span style="color:#008000;"&gt;// assert that the UnitOfWork is reset&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;    var propertyInfo = &lt;span style="color:#0000ff;"&gt;typeof&lt;/span&gt;(UnitOfWork).GetProperty(&lt;span style="color:#006080;"&gt;&amp;quot;CurrentUnitOfWork&amp;quot;&lt;/span&gt;,&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;                        BindingFlags.Static | BindingFlags.SetProperty | BindingFlags.NonPublic);&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;    propertyInfo.SetValue(&lt;span style="color:#0000ff;"&gt;null&lt;/span&gt;, &lt;span style="color:#0000ff;"&gt;null&lt;/span&gt;, &lt;span style="color:#0000ff;"&gt;null&lt;/span&gt;);&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;}&lt;/pre&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;When run, all tests should again pass. So now our implementation of the unit 
of work is thread safe.&lt;/p&gt;
&lt;p&gt;You can find the full code &lt;a href="http://hibernatingrhinos.googlecode.com/svn/trunk/UnitOfWork/"&gt;here&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;</description></item><item><title>NHibernate and the Unit of Work Pattern</title><link>http://nhforge.org/wikis/patternsandpractices/nhibernate-and-the-unit-of-work-pattern/revision/2.aspx</link><pubDate>Tue, 23 Sep 2008 20:02:26 GMT</pubDate><guid isPermaLink="false">45f813f2-f1c4-4eda-a619-288e3cadc793:153</guid><dc:creator>gabriel.schenker</dc:creator><comments>http://nhforge.org/wikis/patternsandpractices/nhibernate-and-the-unit-of-work-pattern/comments.aspx</comments><description>Revision 2 posted to Patterns &amp;amp; Practices by gabriel.schenker on 23/09/2008 05:02:26 p.m.&lt;br /&gt;
&lt;h2&gt;NHibernate and the Unit of Work Pattern&lt;/h2&gt;
&lt;h2&gt;Introduction&lt;/h2&gt;
&lt;p&gt;Martin Fowler &lt;a href="http://martinfowler.com/eaaCatalog/unitOfWork.html"&gt;writes&lt;/a&gt;: &lt;/p&gt;
&lt;p&gt;&amp;quot;When you&amp;#39;re pulling data in and out of a database, it&amp;#39;s important to keep 
track of what you&amp;#39;ve changed; otherwise, that data won&amp;#39;t be written back into 
the database. Similarly you have to insert new objects you create and remove any 
objects you delete.&amp;quot;&lt;/p&gt;
&lt;p&gt;and&lt;/p&gt;
&lt;p&gt;&amp;quot;A &lt;b&gt;Unit of Work&lt;/b&gt; keeps track of everything you do during a 
&lt;i&gt;business transaction&lt;/i&gt; that can affect the database. When you&amp;#39;re done, it 
figures out everything that needs to be done to alter the database as a result 
of your work.&amp;quot;&lt;/p&gt;
&lt;p&gt;In NHibernate we have the &lt;b&gt;Session&lt;/b&gt; object which is a Unit of 
Work (UoW) container. The session object keeps track of all objects you load, 
new objects you add, existing objects you delete and changes you make to any of 
these objects. Only when &lt;b&gt;flushing&lt;/b&gt; the session will the database 
be altered (that is: will the necessary create, update and delete statements be 
sent to the database).&lt;/p&gt;
&lt;p&gt;Now, working directly with the NHibernate session object makes absolute 
sense. But some times you rather want to abstract the data manipulation 
interface from a specific infrastructure implementation &amp;agrave; la NHibernate.&lt;/p&gt;
&lt;p&gt;&lt;b&gt;Note&lt;/b&gt;: most of the design ideas and implementation details 
presented here originate from &lt;a href="http://www.ayende.com/"&gt;Ayende&lt;/a&gt;&amp;#39;s 
UnitOfWork implemented in the &lt;b&gt;Rhino.Commons&lt;/b&gt; which you can get 
&lt;a href="http://rhino-tools.svn.sourceforge.net/svnroot/rhino-tools/trunk"&gt;here&lt;/a&gt;.&lt;/p&gt;
&lt;h2&gt;Design and Implementation (TDD)&lt;/h2&gt;
&lt;h3&gt;Some thought about TDD&lt;/h3&gt;
&lt;p&gt;I want to implement a UnitOfWork pattern for NHibernate and I want to do it 
by using &lt;a href="http://en.wikipedia.org/wiki/Test-driven_development"&gt;TDD&lt;/a&gt;. 
For a beginner (like I was myself not so long ago) it seems unnatural at the 
beginning. We introduce a huge overhead you might think. You might also think 
that we have to write at least double the code as when doing the development 
without TDD. But wait until you have to start to debug your application... or 
until the customer wants to have something changed in the application... or 
until you have to re-factor you application... Then you will immediately see and 
feel the benefits of a good test coverage.&lt;/p&gt;
&lt;h3&gt;Attention: Multi-Threading ahead&lt;/h3&gt;
&lt;p&gt;Please not that the implementation presented here is strictly 
&lt;b&gt;NOT&lt;/b&gt; thread safe!!! I want to reduce the complexity of this 
first implementation. But &lt;b&gt;I promise&lt;/b&gt; that in a following post 
I&amp;#39;ll show you how to make the implementation of the unit of work pattern thread 
safe and thus useful for e.g. Web scenarios.&lt;/p&gt;
&lt;h3&gt;The UnitOfWork Class&lt;/h3&gt;
&lt;p&gt;To start with: I want to have an easy way to &lt;b&gt;start&lt;/b&gt; a new 
UoW, in any place of my application have access to the &lt;b&gt;current&lt;/b&gt; 
UoW and &lt;b&gt;commit&lt;/b&gt; the &lt;i&gt;business transaction&lt;/i&gt; represented by 
my UoW. We can do this with a static class called UnitOfWork&lt;/p&gt;
&lt;p&gt;&lt;a&gt;&lt;span style="text-decoration: line-through; color: red;"&gt;&lt;img style="border-width:0px;" alt="image" border="0" height="179" width="471" /&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;a&gt;&lt;span style="background: SpringGreen;"&gt;&lt;img src="/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/nhibernate.UoW/UoW-UoW_2D00_class.png" alt="" /&gt;&lt;/span&gt;&lt;br /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;The method start creates and returns an instance of a 
&lt;b&gt;UnitOfWorkImplementor&lt;/b&gt; class which implements the interface 
&lt;b&gt;IUnitOfWork&lt;/b&gt;. As you can see then interface IUnitOfWork inherits 
from IDisposable. So we can define that the &lt;i&gt;business transaction&lt;/i&gt; is 
ended when the UoW is disposed. Now, if we do nothing else then nothing should 
happen, that is no changes should be propagated to the database. To commit a 
&lt;i&gt;business transaction&lt;/i&gt; we have to explicitly call a method of the UoW. 
Let&amp;#39;s call this method &lt;b&gt;TransactionalFlush&lt;/b&gt;. In doing so all 
changes recorded by the UoW are committed to the database in one go.&lt;/p&gt;
&lt;p&gt;Now let&amp;#39;s start to implement this! We are doing TDD, aren&amp;#39;t we? So we will 
write our first test (if you are not sure how to best setup a new solution for 
TDD please consult &lt;a href="http://blogs.hibernatingrhinos.com/nhibernate/archive/2008/04/06/how-to-setup-a-new-solution.aspx"&gt;this&lt;/a&gt; 
post). I define a new solution with two projects as follows&lt;/p&gt;
&lt;p&gt;&lt;a&gt;&lt;span style="text-decoration: line-through; color: red;"&gt;&lt;img style="border-width:0px;" alt="image" border="0" height="135" width="304" /&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;a&gt;&lt;span style="background: SpringGreen;"&gt;&lt;img src="/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/nhibernate.UoW/UoW-Solution.png" alt="" /&gt;&lt;/span&gt;&lt;br /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Add a class UnitOfWork_Fixture.cs to the test project and implement the first 
test like this&lt;/p&gt;
&lt;div&gt;
&lt;div style="border-style:none;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;[TestFixture]&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;&lt;span style="color:#0000ff;"&gt;public&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;class&lt;/span&gt; UnitOfWork_Fixture&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;{&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;    &lt;span style="color:#0000ff;"&gt;private&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;readonly&lt;/span&gt; MockRepository _mocks = &lt;span style="color:#0000ff;"&gt;new&lt;/span&gt; MockRepository();&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;&amp;nbsp;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;    [Test]&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;    &lt;span style="color:#0000ff;"&gt;public&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;void&lt;/span&gt; Can_Start_UnitOfWork()&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;    {&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;        IUnitOfWork uow = UnitOfWork.Start();&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;    }&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;}&lt;/pre&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;Of course this test will not compile since you don&amp;#39;t have the types 
UnitOfWork and IUnitOfWork defined yet. Let &lt;a href="http://www.jetbrains.com/resharper/"&gt;Resharper&lt;/a&gt; create them for you (or 
implement them by hand)&lt;/p&gt;
&lt;div&gt;
&lt;div style="border-style:none;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;&lt;span style="color:#0000ff;"&gt;public&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;static&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;class&lt;/span&gt; UnitOfWork&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;{&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;    &lt;span style="color:#0000ff;"&gt;public&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;static&lt;/span&gt; IUnitOfWork Start()&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;    {&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;        &lt;span style="color:#0000ff;"&gt;throw&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;new&lt;/span&gt; NotImplementedException();&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;    }&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;&amp;nbsp;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;    &lt;span style="color:#0000ff;"&gt;public&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;static&lt;/span&gt; IUnitOfWork Current { get; &lt;span style="color:#0000ff;"&gt;private&lt;/span&gt; set; }&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;}&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;&amp;nbsp;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;&lt;span style="color:#0000ff;"&gt;public&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;interface&lt;/span&gt; IUnitOfWork : IDisposable&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;{&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;}&lt;/pre&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;Now the test will compile but it will fail! Of course, you haven&amp;#39;t 
implemented the Start method so far. In this method we must now create a new UoW 
and return it to the caller. A UoW is a complex beast and should therefore be 
constructed in a factory. So let&amp;#39;s define a factory Interface IUnitOfWorkFactory 
with a method Create which returns a UoW implementing the interface 
IUnitOfWork.&lt;/p&gt;
&lt;div&gt;
&lt;div style="border-style:none;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;&lt;span style="color:#0000ff;"&gt;public&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;interface&lt;/span&gt; IUnitOfWorkFactory&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;{&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;  IUnitOfWork Create();&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;}&lt;/pre&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;since we want to test our UnitOfWork class in isolation we have to mock all 
other dependencies line the unit of work factory. I&amp;#39;ll use 
&lt;b&gt;Rhino.Mocks&lt;/b&gt; as my mocking framework (Please refer to 
documentation &lt;a href="http://www.ayende.com/wiki/Rhino+Mocks+Documentation.ashx"&gt;here&lt;/a&gt;). I 
want to test that when calling the start method of the UnitOfWork class the 
factory gets called. So I extend my test function&lt;/p&gt;
&lt;div&gt;
&lt;div style="border-style:none;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;[Test]&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;&lt;span style="color:#0000ff;"&gt;public&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;void&lt;/span&gt; Can_Start_UnitOfWork()&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;{&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;    var factory = _mocks.DynamicMock&amp;lt;IUnitOfWorkFactory&amp;gt;();&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;    var unitOfWork = _mocks.DynamicMock&amp;lt;IUnitOfWork&amp;gt;();&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;&amp;nbsp;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;    &lt;span style="color:#008000;"&gt;// brute force attack to set my own factory via reflection&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;    var fieldInfo = &lt;span style="color:#0000ff;"&gt;typeof&lt;/span&gt;(UnitOfWork).GetField(&lt;span style="color:#006080;"&gt;&amp;quot;_unitOfWorkFactory&amp;quot;&lt;/span&gt;, &lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;        BindingFlags.Static | BindingFlags.SetField | BindingFlags.NonPublic);&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;    fieldInfo.SetValue(&lt;span style="color:#0000ff;"&gt;null&lt;/span&gt;, factory);&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;&amp;nbsp;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;    &lt;span style="color:#0000ff;"&gt;using&lt;/span&gt;(_mocks.Record())&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;    {&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;        Expect.Call(factory.Create()).Return(unitOfWork);&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;    }&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;    &lt;span style="color:#0000ff;"&gt;using&lt;/span&gt;(_mocks.Playback())&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;    {&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;        var uow = UnitOfWork.Start();&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;    }&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;}&lt;/pre&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;In the first two lines of code I mock the external dependencies of the 
UnitOfWork class. Then I do something you should not do very often (but I have 
good reasons doing so here and I promise it&amp;#39;s the only time I&amp;#39;ll do it in this 
project...). I set a private field of the UnitOfWork class with a value by using 
reflection. I could implement a public setter in the class but as I would only 
need it for this test and I want to keep the class interface as simple as 
possible I chose to do it via reflection.&lt;/p&gt;
&lt;p&gt;In the&amp;nbsp; record phase I define my expectation (namely that the factory create 
method is called) and in the playback phase I invoke the Start method which I 
want to test. The test will compile but fail to execute. I have not yet defined 
the private static field _unitOfWorkFactory and I also do not call the factory. 
So let&amp;#39;s modify our code...&lt;/p&gt;
&lt;div&gt;
&lt;div style="border-style:none;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;&lt;span style="color:#0000ff;"&gt;public&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;static&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;class&lt;/span&gt; UnitOfWork&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;{&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;    &lt;span style="color:#0000ff;"&gt;private&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;static&lt;/span&gt; IUnitOfWorkFactory _unitOfWorkFactory;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;    &lt;span style="color:#0000ff;"&gt;private&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;static&lt;/span&gt; IUnitOfWork _innerUnitOfWork;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;&amp;nbsp;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;    &lt;span style="color:#0000ff;"&gt;public&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;static&lt;/span&gt; IUnitOfWork Start()&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;    {&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;        _innerUnitOfWork = _unitOfWorkFactory.Create();&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;        &lt;span style="color:#0000ff;"&gt;return&lt;/span&gt; _innerUnitOfWork;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;    }&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;&amp;nbsp;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;    &lt;span style="color:#0000ff;"&gt;public&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;static&lt;/span&gt; IUnitOfWork Current { get; &lt;span style="color:#0000ff;"&gt;private&lt;/span&gt; set; }&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;}&lt;/pre&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;now the test will pass.&lt;/p&gt;
&lt;p&gt;Since in all our test regarding the UnitOfWork class we will always need it 
with an injected factory we define a new test fixture with a context setup for 
our specific needs. We put the respective code in the 
&lt;b&gt;SetupContext&lt;/b&gt; and &lt;b&gt;TearDownContext&lt;/b&gt; methods&lt;/p&gt;
&lt;div&gt;
&lt;div style="border-style:none;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;[TestFixture]&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;&lt;span style="color:#0000ff;"&gt;public&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;class&lt;/span&gt; UnitOfWork_With_Factory_Fixture&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;{&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;    &lt;span style="color:#0000ff;"&gt;private&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;readonly&lt;/span&gt; MockRepository _mocks = &lt;span style="color:#0000ff;"&gt;new&lt;/span&gt; MockRepository();&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;    &lt;span style="color:#0000ff;"&gt;private&lt;/span&gt; IUnitOfWorkFactory _factory;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;    &lt;span style="color:#0000ff;"&gt;private&lt;/span&gt; IUnitOfWork _unitOfWork;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;&amp;nbsp;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;    [SetUp]&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;    &lt;span style="color:#0000ff;"&gt;public&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;void&lt;/span&gt; SetupContext()&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;    {&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;        _factory = _mocks.DynamicMock&amp;lt;IUnitOfWorkFactory&amp;gt;();&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;        _unitOfWork = _mocks.DynamicMock&amp;lt;IUnitOfWork&amp;gt;();&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;&amp;nbsp;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;        &lt;span style="color:#008000;"&gt;// brute force attack to set my own factory via reflection&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;        var fieldInfo = &lt;span style="color:#0000ff;"&gt;typeof&lt;/span&gt;(UnitOfWork).GetField(&lt;span style="color:#006080;"&gt;&amp;quot;_unitOfWorkFactory&amp;quot;&lt;/span&gt;,&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;            BindingFlags.Static | BindingFlags.SetField | BindingFlags.NonPublic);&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;        fieldInfo.SetValue(&lt;span style="color:#0000ff;"&gt;null&lt;/span&gt;, _factory);&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;&amp;nbsp;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;        _mocks.BackToRecordAll();&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;        SetupResult.For(_factory.Create()).Return(_unitOfWork);&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;        _mocks.ReplayAll();&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;    }&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;&amp;nbsp;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;    [TearDown]&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;    &lt;span style="color:#0000ff;"&gt;public&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;void&lt;/span&gt; TearDownContext()&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;    {&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;        _mocks.VerifyAll();&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;    }&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;}&lt;/pre&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;&lt;b&gt;Note&lt;/b&gt;: in the second last line of the 
&lt;b&gt;SetupContext&lt;/b&gt; method we define that each time the method Create 
of the factory object is called (by the UnitOfWork Start method) we want it to 
return our predefined mocked _&lt;b&gt;unitOfWork&lt;/b&gt; instance.&lt;/p&gt;
&lt;p&gt;Trying to start a UoW if there is already one active should throw a 
meaningful exception. This is the test&lt;/p&gt;
&lt;div&gt;
&lt;div style="border-style:none;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;[Test]&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;&lt;span style="color:#0000ff;"&gt;public&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;void&lt;/span&gt; Starting_UnitOfWork_if_already_started_throws()&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;{&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;    UnitOfWork.Start();&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;    &lt;span style="color:#0000ff;"&gt;try&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;    {&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;        UnitOfWork.Start();&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;    }&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;    &lt;span style="color:#0000ff;"&gt;catch&lt;/span&gt; (InvalidOperationException ex)&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;    { }&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;}&lt;/pre&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;As a consequence we have to extend our Start method in the UnitOfWork 
class&lt;/p&gt;
&lt;div&gt;
&lt;div style="border-style:none;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;&lt;span style="color:#0000ff;"&gt;public&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;static&lt;/span&gt; IUnitOfWork Start()&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;{&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;    &lt;span style="color:#0000ff;"&gt;if&lt;/span&gt; (_innerUnitOfWork != &lt;span style="color:#0000ff;"&gt;null&lt;/span&gt;)&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;        &lt;span style="color:#0000ff;"&gt;throw&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;new&lt;/span&gt; InvalidOperationException(&lt;span style="color:#006080;"&gt;&amp;quot;You cannot start more than one unit of work at the same time.&amp;quot;&lt;/span&gt;);&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;    &lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;    _innerUnitOfWork = _unitOfWorkFactory.Create();&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;    &lt;span style="color:#0000ff;"&gt;return&lt;/span&gt; _innerUnitOfWork;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;}&lt;/pre&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;Now I have another problem: After the test is finished the static field 
_&lt;b&gt;innerUnitOfWork&lt;/b&gt; of my &lt;b&gt;UnitOfWork&lt;/b&gt; class is set 
to a value other than &lt;b&gt;null&lt;/b&gt;. This will have a undesired side 
effect to the following test. I have to reset this field. Again in this special 
case I&amp;#39;ll do it via reflection to not clutter the interface of my class (static 
classes are difficult more complex to deal with in TDD than non static 
classes...). We do reset our UnitOfWork class in the TearDownContext method&lt;/p&gt;
&lt;div&gt;
&lt;div style="border-style:none;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;[TearDown]&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;&lt;span style="color:#0000ff;"&gt;public&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;void&lt;/span&gt; TearDownContext()&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;{&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;    _mocks.VerifyAll();&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;&amp;nbsp;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;    &lt;span style="color:#008000;"&gt;// assert that the UnitOfWork is reset&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;    var fieldInfo = &lt;span style="color:#0000ff;"&gt;typeof&lt;/span&gt;(UnitOfWork).GetField(&lt;span style="color:#006080;"&gt;&amp;quot;_innerUnitOfWork&amp;quot;&lt;/span&gt;,&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;        BindingFlags.Static | BindingFlags.SetField | BindingFlags.NonPublic);&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;    fieldInfo.SetValue(&lt;span style="color:#0000ff;"&gt;null&lt;/span&gt;, &lt;span style="color:#0000ff;"&gt;null&lt;/span&gt;);&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;}&lt;/pre&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;Next we want to be able to access the current unit of work. As usual we first 
implement a test&lt;/p&gt;
&lt;div&gt;
&lt;div style="border-style:none;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;[Test]&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;&lt;span style="color:#0000ff;"&gt;public&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;void&lt;/span&gt; Can_access_current_unit_of_work()&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;{&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;    IUnitOfWork uow = UnitOfWork.Start();&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;    var current = UnitOfWork.Current;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;    Assert.AreSame(uow, current);&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;}&lt;/pre&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;You can figure out what code you need to implement for the test to pass.&lt;/p&gt;
&lt;p&gt;We also want to assert that when accessing the current UoW if no UoW has been 
started that a meaningful exception is thrown&lt;/p&gt;
&lt;div&gt;
&lt;div style="border-style:none;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;[Test]&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;&lt;span style="color:#0000ff;"&gt;public&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;void&lt;/span&gt; Accessing_Current_UnitOfWork_if_not_started_throws()&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;{&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;    &lt;span style="color:#0000ff;"&gt;try&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;    {&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;        var current = UnitOfWork.Current;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;    }&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;    &lt;span style="color:#0000ff;"&gt;catch&lt;/span&gt; (InvalidOperationException ex)&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;    { }&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;}&lt;/pre&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;now my implementation of the Current property in the UnitOfWork class is as 
follows&lt;/p&gt;
&lt;div&gt;
&lt;div style="border-style:none;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;&lt;span style="color:#0000ff;"&gt;public&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;static&lt;/span&gt; IUnitOfWork Current&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;{&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;    get&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;    {&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;        &lt;span style="color:#0000ff;"&gt;if&lt;/span&gt; (_innerUnitOfWork == &lt;span style="color:#0000ff;"&gt;null&lt;/span&gt;)&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;            &lt;span style="color:#0000ff;"&gt;throw&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;new&lt;/span&gt; InvalidOperationException(&lt;span style="color:#006080;"&gt;&amp;quot;You are not in a unit of work.&amp;quot;&lt;/span&gt;);&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;        &lt;span style="color:#0000ff;"&gt;return&lt;/span&gt; _innerUnitOfWork;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;    }&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;}&lt;/pre&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;Next we want a property on the class which tells us whether a UoW is started 
or not. The test for it&lt;/p&gt;
&lt;div&gt;
&lt;div style="border-style:none;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;[Test]&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;&lt;span style="color:#0000ff;"&gt;public&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;void&lt;/span&gt; Can_test_if_UnitOfWork_Is_Started()&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;{&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;    Assert.IsFalse(UnitOfWork.IsStarted);&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;&amp;nbsp;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;    IUnitOfWork uow = UnitOfWork.Start();&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;    Assert.IsTrue(UnitOfWork.IsStarted);&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;}&lt;/pre&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;It&amp;#39;s getting boring isn&amp;#39;t it... But this is the way &lt;b&gt;TDD&lt;/b&gt; 
works. You always think (hard) on what you need and then you implement the test 
with which you can proof that you get it as you want it. Only then you implement 
the functionality needed to fulfill the test. If you do so you automatically 
follow the &lt;b&gt;YAGNI&lt;/b&gt; principle (you ain&amp;#39;t gona need it) that is you 
only implement the code you really need!&lt;/p&gt;
&lt;p&gt;We can fulfill the test like so&lt;/p&gt;
&lt;div&gt;
&lt;div style="border-style:none;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;&lt;span style="color:#0000ff;"&gt;public&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;static&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;bool&lt;/span&gt; IsStarted&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;{&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;    get { &lt;span style="color:#0000ff;"&gt;return&lt;/span&gt; _innerUnitOfWork != &lt;span style="color:#0000ff;"&gt;null&lt;/span&gt;; }&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;}&lt;/pre&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;The UnitOfWork class is now a perfect wrapper for the NHibernate session 
object. Though for some advance scenarios I would like to have access to the 
session object related to my UoW. As a consequence I&amp;#39;ll implement a read only 
property CurrentSession in the UnitOfWork class. Lets again start with the 
test&lt;/p&gt;
&lt;div&gt;
&lt;div style="border-style:none;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;[Test]&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;&lt;span style="color:#0000ff;"&gt;public&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;void&lt;/span&gt; Can_get_valid_current_session_if_UoW_is_started()&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;{&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;    &lt;span style="color:#0000ff;"&gt;using&lt;/span&gt; (UnitOfWork.Start())&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;    {&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;        ISession session = UnitOfWork.CurrentSession;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;        Assert.IsNotNull(session);&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;    }&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;}&lt;/pre&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;and the implementation&lt;/p&gt;
&lt;div&gt;
&lt;div style="border-style:none;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;&lt;span style="color:#0000ff;"&gt;public&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;static&lt;/span&gt; ISession CurrentSession&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;{&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;    get { &lt;span style="color:#0000ff;"&gt;return&lt;/span&gt; _unitOfWorkFactory.CurrentSession; }&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;    &lt;span style="color:#0000ff;"&gt;internal&lt;/span&gt; set { _unitOfWorkFactory.CurrentSession = &lt;span style="color:#0000ff;"&gt;value&lt;/span&gt;; }&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;}&lt;/pre&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;Note that I have just delegated the call to the factory class. Thus to make 
the test pass I have to add two additional lines to the SetupContext method of 
the test fixture where I mock a session object and setup the result for a call 
to the property CurrentSession of the factory.&lt;/p&gt;
&lt;div&gt;
&lt;div style="border-style:none;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;[SetUp]&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;&lt;span style="color:#0000ff;"&gt;public&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;void&lt;/span&gt; SetupContext()&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;{&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;    _factory = _mocks.DynamicMock&amp;lt;IUnitOfWorkFactory&amp;gt;();&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;    _unitOfWork = _mocks.DynamicMock&amp;lt;IUnitOfWork&amp;gt;();&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;    _session = _mocks.DynamicMock&amp;lt;ISession&amp;gt;();&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;&amp;nbsp;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;    &lt;span style="color:#008000;"&gt;// brute force attack to set my own factory via reflection&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;    var fieldInfo = &lt;span style="color:#0000ff;"&gt;typeof&lt;/span&gt;(UnitOfWork).GetField(&lt;span style="color:#006080;"&gt;&amp;quot;_unitOfWorkFactory&amp;quot;&lt;/span&gt;,&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;        BindingFlags.Static | BindingFlags.SetField | BindingFlags.NonPublic);&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;    fieldInfo.SetValue(&lt;span style="color:#0000ff;"&gt;null&lt;/span&gt;, _factory);&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;&amp;nbsp;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;    _mocks.BackToRecordAll();&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;    SetupResult.For(_factory.Create()).Return(_unitOfWork);&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;    SetupResult.For(_factory.CurrentSession).Return(_session);&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;    _mocks.ReplayAll();&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;}&lt;/pre&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;That&amp;#39;s all we need for the moment regarding the UnitOfWork class. Next topics 
will be the the implementation of the UnitOfWorkFactory class and then of the 
UnitOfWorkImplementor class. The details will be presented in the next post to 
this blog. So keep ready...&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;h1&gt;Part 2&lt;/h1&gt;
&lt;h2&gt;Design and Implementation&lt;/h2&gt;
&lt;h3&gt;The Unit Of Work Factory&lt;/h3&gt;
&lt;p&gt;The creation of a unit of work instance is a complex process and as such is a 
good candidate for a factory.&lt;/p&gt;
&lt;p&gt;Since a UoW (Unit of Work) is basically a wrapper around a NHibernate session 
object I&amp;#39;ll need to open such a session whenever I start a new UoW. But to be 
able to get such a session NHibernate has to be configured and a NHibernate 
Session Factory has to be available. The interface of my UoW factory is defined 
as follows&lt;/p&gt;
&lt;p&gt;&lt;a&gt;&lt;span style="text-decoration: line-through; color: red;"&gt;&lt;img style="border-width:0px;" alt="image" border="0" height="236" width="214" /&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="background: SpringGreen;"&gt;&lt;img src="/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/nhibernate.UoW/UoW-UoW_2D00_Factory.png" alt="" /&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="background: SpringGreen;"&gt;I&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;basically&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;have&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;two&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;public&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;methods&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;on&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;my&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;factory&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;.&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;One&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;for&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;the&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;creation&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;of&lt;/span&gt; 
&lt;span style="background: SpringGreen;"&gt;the&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;UoW&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;and&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;the&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;second&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;for&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;the&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;disposal&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;of&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;a&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;specific&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;UoW&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;instance&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;.&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;The&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;disposal&lt;/span&gt; 
&lt;span style="background: SpringGreen;"&gt;involves&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;also&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;some&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;work&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;and&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;thus&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;justifies&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;the&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;existence&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;of&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;this&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;second&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;factory&lt;/span&gt; 
&lt;span style="background: SpringGreen;"&gt;method&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;.&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;The&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;3&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;properties&lt;/span&gt; &lt;b&gt;&lt;span style="background: SpringGreen;"&gt;Configuration&lt;/span&gt;&lt;/b&gt;&lt;span style="background: SpringGreen;"&gt;,&lt;/span&gt; 
&lt;b&gt;&lt;span style="background: SpringGreen;"&gt;SessionFactory&lt;/span&gt;&lt;/b&gt; &lt;span style="background: SpringGreen;"&gt;and&lt;/span&gt; &lt;b&gt;&lt;span style="background: SpringGreen;"&gt;CurrentSession&lt;/span&gt;&lt;/b&gt; &lt;span style="background: SpringGreen;"&gt;are&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;there&lt;/span&gt; 
&lt;span style="background: SpringGreen;"&gt;mostly&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;for&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;advanced&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;scenarios&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;(&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;and&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;as&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;such&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;could&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;theoretically&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;be&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;omitted&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;in&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;a&lt;/span&gt; 
&lt;span style="background: SpringGreen;"&gt;first&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;simple&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;implementation)&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="background: SpringGreen;"&gt;Let&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;&amp;#39;&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;s&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;now&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;write&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;the&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;test&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;for&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;the&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;Create&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;method&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;of&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;the&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;UoW&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;factory&lt;/span&gt; 
&lt;span style="background: SpringGreen;"&gt;implementation&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;.&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;At&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;first&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;I&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;prepare&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;a&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;new&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;test&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;fixture&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;class&lt;/span&gt;&lt;/p&gt;
&lt;div&gt;
&lt;div style="border-style:none;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;&lt;span style="color:#0000ff;"&gt;&lt;span style="background: SpringGreen;"&gt;using&lt;/span&gt;&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;System&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;;&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;&lt;span style="color:#0000ff;"&gt;&lt;span style="background: SpringGreen;"&gt;using&lt;/span&gt;&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;NHibernate&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;;&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;&lt;span style="color:#0000ff;"&gt;&lt;span style="background: SpringGreen;"&gt;using&lt;/span&gt;&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;NUnit.Framework&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;;&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;&amp;nbsp;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;&lt;span style="color:#0000ff;"&gt;&lt;span style="background: SpringGreen;"&gt;namespace&lt;/span&gt;&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;NHibernateUnitOfWork.Tests&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;&lt;span style="background: SpringGreen;"&gt;{&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;    &lt;span style="background: SpringGreen;"&gt;[&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;TestFixture]&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;    &lt;span style="color:#0000ff;"&gt;&lt;span style="background: SpringGreen;"&gt;public&lt;/span&gt;&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;&lt;span style="background: SpringGreen;"&gt;class&lt;/span&gt;&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;UnitOfWorkFactory_Fixture&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;    &lt;span style="background: SpringGreen;"&gt;{&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;        &lt;span style="color:#0000ff;"&gt;&lt;span style="background: SpringGreen;"&gt;private&lt;/span&gt;&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;IUnitOfWorkFactory&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;_&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;factory;&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;&amp;nbsp;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;        &lt;span style="background: SpringGreen;"&gt;[&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;SetUp]&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;        &lt;span style="color:#0000ff;"&gt;&lt;span style="background: SpringGreen;"&gt;public&lt;/span&gt;&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;&lt;span style="background: SpringGreen;"&gt;void&lt;/span&gt;&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;SetupContext(&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;)&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;        &lt;span style="background: SpringGreen;"&gt;{&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;            &lt;span style="background: SpringGreen;"&gt;_&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;factory&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;=&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;(&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;IUnitOfWorkFactory)&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;Activator.CreateInstance&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;(&lt;/span&gt;&lt;span style="color:#0000ff;"&gt;&lt;span style="background: SpringGreen;"&gt;typeof&lt;/span&gt;&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;(&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;UnitOfWorkFactory),&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;&lt;span style="background: SpringGreen;"&gt;true&lt;/span&gt;&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;)&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;;&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;        &lt;span style="background: SpringGreen;"&gt;}&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;    &lt;span style="background: SpringGreen;"&gt;}&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;&lt;span style="background: SpringGreen;"&gt;}&lt;/span&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;&lt;span style="background: SpringGreen;"&gt;Why&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;the&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;heck&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;do&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;I&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;need&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;the&lt;/span&gt; &lt;b&gt;&lt;span style="background: SpringGreen;"&gt;Activator.CreateInstance&lt;/span&gt;&lt;/b&gt; &lt;span style="background: SpringGreen;"&gt;to&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;get&lt;/span&gt; 
&lt;span style="background: SpringGreen;"&gt;an&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;instance&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;of&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;the&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;factory&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;?&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;Well&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;I&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;decided&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;that&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;the&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;construction&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;of&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;a&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;new&lt;/span&gt; 
&lt;span style="background: SpringGreen;"&gt;factory&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;instance&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;should&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;be&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;internal&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;to&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;the&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;assembly&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;implementing&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;the&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;Unit&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;of&lt;/span&gt; 
&lt;span style="background: SpringGreen;"&gt;Work&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;pattern&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;.&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;Thus&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;the&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;(&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;default)&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;constructor&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;of&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;the&lt;/span&gt; 
&lt;b&gt;&lt;span style="background: SpringGreen;"&gt;UnitOfWorkFactory&lt;/span&gt;&lt;/b&gt; &lt;span style="background: SpringGreen;"&gt;class&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;has&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;a&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;modifier&lt;/span&gt; 
&lt;b&gt;&lt;span style="background: SpringGreen;"&gt;internal&lt;/span&gt;&lt;/b&gt; &lt;span style="background: SpringGreen;"&gt;and&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;as&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;a&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;consequence&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;cannot&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;be&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;used&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;from&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;code&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;outside&lt;/span&gt; 
&lt;span style="background: SpringGreen;"&gt;the&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;assembly&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;in&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;which&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;the&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;factory&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;is&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;implemented&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;.&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;But&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;I&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;need&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;an&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;instance&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;when&lt;/span&gt; 
&lt;span style="background: SpringGreen;"&gt;testing&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;and&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;thus&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;have&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;to&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;resort&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;to&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;the&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;technique&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;used&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;above&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="background: SpringGreen;"&gt;Now&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;the&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;question&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;is&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;:&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;&amp;quot;what&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;confirms&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;me&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;that&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;the&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;method&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;Create&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;of&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;the&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;factory&lt;/span&gt; 
&lt;span style="background: SpringGreen;"&gt;works&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;as&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;expected&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;?&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;&amp;quot;.&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;I&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;have&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;chosen&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;the&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;following&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;:&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;I&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;expect&lt;/span&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;span style="background: SpringGreen;"&gt;the&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;method&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;returning&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;a&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;non&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;null&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;instance&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;of&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;type&lt;/span&gt; 
&lt;b&gt;&lt;span style="background: SpringGreen;"&gt;IUnitOfWork&lt;/span&gt;&lt;/b&gt; 
&lt;/li&gt;
&lt;li&gt;&lt;span style="background: SpringGreen;"&gt;the&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;returned&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;instance&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;having&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;a&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;non&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;null&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;(&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;NHibernate)&lt;/span&gt; 
&lt;b&gt;&lt;span style="background: SpringGreen;"&gt;session&lt;/span&gt;&lt;/b&gt; 
&lt;/li&gt;
&lt;li&gt;&lt;span style="background: SpringGreen;"&gt;the&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;(&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;NHibernate)&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;session&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;having&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;the&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;Flush&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;Mode&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;set&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;to&lt;/span&gt; 
&lt;b&gt;&lt;span style="background: SpringGreen;"&gt;commit&lt;/span&gt;&lt;/b&gt; &lt;span style="background: SpringGreen;"&gt;(&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;that&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;is&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;:&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;the&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;session&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;is&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;never&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;flushed&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;except&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;when&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;I&lt;/span&gt; 
&lt;span style="background: SpringGreen;"&gt;explicitly&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;commit&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;a&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;transaction&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;-&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;see&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;the&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;NHibernate&lt;/span&gt; &lt;a href="http://www.hibernate.org/5.html#A25"&gt;&lt;span style="background: SpringGreen;"&gt;documentation&lt;/span&gt;&lt;/a&gt; &lt;span style="background: SpringGreen;"&gt;for&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;any&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;details&lt;/span&gt; 
&lt;span style="background: SpringGreen;"&gt;about&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;the&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;Flush&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;Mode&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;)&lt;/span&gt; &lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;span style="background: SpringGreen;"&gt;Now&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;the&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;code&lt;/span&gt;&lt;/p&gt;
&lt;div&gt;
&lt;div style="border-style:none;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;&lt;span style="background: SpringGreen;"&gt;[&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;Test]&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;&lt;span style="color:#0000ff;"&gt;&lt;span style="background: SpringGreen;"&gt;public&lt;/span&gt;&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;&lt;span style="background: SpringGreen;"&gt;void&lt;/span&gt;&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;Can_create_unit_of_work(&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;)&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;&lt;span style="background: SpringGreen;"&gt;{&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;    &lt;span style="background: SpringGreen;"&gt;IUnitOfWork&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;implementor&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;=&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;_&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;factory.Create();&lt;/span&gt; &lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;    &lt;span style="background: SpringGreen;"&gt;Assert.IsNotNull(implementor)&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;;&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;    &lt;span style="background: SpringGreen;"&gt;Assert.IsNotNull(_factory.CurrentSession)&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;;&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;    &lt;span style="background: SpringGreen;"&gt;Assert.AreEqual(FlushMode.Commit&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;,&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;_&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;factory.CurrentSession.FlushMode);&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;&lt;span style="background: SpringGreen;"&gt;}&lt;/span&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;&lt;span style="background: SpringGreen;"&gt;and&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;the&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;implementation&lt;/span&gt;&lt;/p&gt;
&lt;div&gt;
&lt;div style="border-style:none;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;&lt;span style="color:#0000ff;"&gt;&lt;span style="background: SpringGreen;"&gt;public&lt;/span&gt;&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;&lt;span style="background: SpringGreen;"&gt;class&lt;/span&gt;&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;UnitOfWorkFactory&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;:&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;IUnitOfWorkFactory&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;&lt;span style="background: SpringGreen;"&gt;{&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;    &lt;span style="color:#0000ff;"&gt;&lt;span style="background: SpringGreen;"&gt;private&lt;/span&gt;&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;&lt;span style="background: SpringGreen;"&gt;static&lt;/span&gt;&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;ISession&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;_&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;currentSession;&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;    &lt;span style="color:#0000ff;"&gt;&lt;span style="background: SpringGreen;"&gt;private&lt;/span&gt;&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;ISessionFactory&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;_&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;sessionFactory;&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;&amp;nbsp;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;    &lt;span style="color:#0000ff;"&gt;&lt;span style="background: SpringGreen;"&gt;internal&lt;/span&gt;&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;UnitOfWorkFactory(&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;)&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;    &lt;span style="background: SpringGreen;"&gt;{&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;}&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;&amp;nbsp;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;    &lt;span style="color:#0000ff;"&gt;&lt;span style="background: SpringGreen;"&gt;public&lt;/span&gt;&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;IUnitOfWork&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;Create(&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;)&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;    &lt;span style="background: SpringGreen;"&gt;{&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;        &lt;span style="background: SpringGreen;"&gt;ISession&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;session&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;=&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;CreateSession()&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;;&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;        &lt;span style="background: SpringGreen;"&gt;session.FlushMode&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;=&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;FlushMode.Commit&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;;&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;        &lt;span style="background: SpringGreen;"&gt;_&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;currentSession&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;=&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;session&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;;&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;        &lt;span style="color:#0000ff;"&gt;&lt;span style="background: SpringGreen;"&gt;return&lt;/span&gt;&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;&lt;span style="background: SpringGreen;"&gt;new&lt;/span&gt;&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;UnitOfWorkImplementor&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;(&lt;/span&gt;&lt;span style="color:#0000ff;"&gt;&lt;span style="background: SpringGreen;"&gt;this&lt;/span&gt;&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;,&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;session)&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;;&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;    &lt;span style="background: SpringGreen;"&gt;}&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;&lt;span style="background: SpringGreen;"&gt;}&lt;/span&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;&lt;span style="background: SpringGreen;"&gt;As&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;you&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;can&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;see&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;I&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;first&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;need&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;a&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;new&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;session&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;instance&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;.&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;I&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;then&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;set&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;the&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;flush&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;mode&lt;/span&gt; 
&lt;span style="background: SpringGreen;"&gt;to&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;commit&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;and&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;assign&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;the&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;session&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;to&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;an&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;instance&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;variable&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;for&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;further&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;use&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;.&lt;/span&gt; 
&lt;span style="background: SpringGreen;"&gt;Finally&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;I&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;return&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;a&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;new&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;instance&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;of&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;the&lt;/span&gt; &lt;b&gt;&lt;span style="background: SpringGreen;"&gt;UnitOfWorkImplementor&lt;/span&gt;&lt;/b&gt; 
&lt;span style="background: SpringGreen;"&gt;(&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;which&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;implements&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;the&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;interface&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;IUnitOfWork)&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;.&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;The&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;constructor&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;of&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;the&lt;/span&gt; 
&lt;b&gt;&lt;span style="background: SpringGreen;"&gt;UnitOfWorkImplementor&lt;/span&gt;&lt;/b&gt; &lt;span style="background: SpringGreen;"&gt;class&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;requires&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;two&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;parameters&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;,&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;the&lt;/span&gt; 
&lt;span style="background: SpringGreen;"&gt;session&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;and&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;a&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;reference&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;to&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;this&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;factory&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="background: SpringGreen;"&gt;To&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;be&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;able&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;to&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;compile&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;I&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;also&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;have&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;to&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;define&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;the&lt;/span&gt; 
&lt;b&gt;&lt;span style="background: SpringGreen;"&gt;UnitOfWorkImplementor&lt;/span&gt;&lt;/b&gt; &lt;span style="background: SpringGreen;"&gt;class&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;.&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;Of&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;this&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;class&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;I&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;just&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;implement&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;the&lt;/span&gt; 
&lt;span style="background: SpringGreen;"&gt;minimum&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;needed&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;so&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;far&lt;/span&gt;&lt;/p&gt;
&lt;div&gt;
&lt;div style="border-style:none;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;&lt;span style="color:#0000ff;"&gt;&lt;span style="background: SpringGreen;"&gt;public&lt;/span&gt;&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;&lt;span style="background: SpringGreen;"&gt;class&lt;/span&gt;&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;UnitOfWorkImplementor&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;:&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;IUnitOfWork&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;&lt;span style="background: SpringGreen;"&gt;{&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;    &lt;span style="color:#0000ff;"&gt;&lt;span style="background: SpringGreen;"&gt;private&lt;/span&gt;&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;&lt;span style="background: SpringGreen;"&gt;readonly&lt;/span&gt;&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;IUnitOfWorkFactory&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;_&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;factory;&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;    &lt;span style="color:#0000ff;"&gt;&lt;span style="background: SpringGreen;"&gt;private&lt;/span&gt;&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;&lt;span style="background: SpringGreen;"&gt;readonly&lt;/span&gt;&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;ISession&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;_&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;session;&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;&amp;nbsp;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;    &lt;span style="color:#0000ff;"&gt;&lt;span style="background: SpringGreen;"&gt;public&lt;/span&gt;&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;UnitOfWorkImplementor(IUnitOfWorkFactory&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;factory&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;,&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;ISession&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;session&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;)&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;    &lt;span style="background: SpringGreen;"&gt;{&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;        &lt;span style="background: SpringGreen;"&gt;_&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;factory&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;=&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;factory&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;;&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;        &lt;span style="background: SpringGreen;"&gt;_&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;session&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;=&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;session&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;;&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;    &lt;span style="background: SpringGreen;"&gt;}&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;&lt;span style="background: SpringGreen;"&gt;}&lt;/span&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;&lt;span style="background: SpringGreen;"&gt;Now&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;back&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;to&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;the&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;implementation&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;of&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;the&lt;/span&gt; &lt;b&gt;&lt;span style="background: SpringGreen;"&gt;CreateSession&lt;/span&gt;&lt;/b&gt; &lt;span style="background: SpringGreen;"&gt;method&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;.&lt;/span&gt; 
&lt;span style="background: SpringGreen;"&gt;To&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;be&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;able&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;to&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;create&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;(&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;and&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;open&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;)&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;a&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;session&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;NHibernate&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;must&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;have&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;been&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;configured&lt;/span&gt; 
&lt;span style="background: SpringGreen;"&gt;previously&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;.&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;So&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;I&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;solve&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;this&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;problem&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;first&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;.&lt;/span&gt; &lt;/p&gt;
&lt;p&gt;&lt;span style="background: SpringGreen;"&gt;First&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;we&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;add&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;a&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;file&lt;/span&gt; &lt;b&gt;&lt;span style="background: SpringGreen;"&gt;hibernate.cfg.xml&lt;/span&gt;&lt;/b&gt; &lt;span style="background: SpringGreen;"&gt;to&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;our&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;test&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;project&lt;/span&gt; 
&lt;span style="background: SpringGreen;"&gt;and&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;put&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;the&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;following&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;content&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;into&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;it&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;(&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;don&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;&amp;#39;&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;t&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;forget&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;to&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;set&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;the&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;property&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;&amp;#39;&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;Copy&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;to&lt;/span&gt; 
&lt;span style="background: SpringGreen;"&gt;Output&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;Directory&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;&amp;#39;&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;of&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;this&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;file&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;to&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;&amp;#39;&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;Copy&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;always&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;&amp;#39;&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;)&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;.&lt;/span&gt;&lt;/p&gt;
&lt;div&gt;
&lt;div style="border-style:none;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;&lt;span style="color:#0000ff;"&gt;&lt;span style="background: SpringGreen;"&gt;&amp;lt;?&lt;/span&gt;&lt;/span&gt;&lt;span style="color:#800000;"&gt;&lt;span style="background: SpringGreen;"&gt;xml&lt;/span&gt;&lt;/span&gt; &lt;span style="color:#ff0000;"&gt;&lt;span style="background: SpringGreen;"&gt;version&lt;/span&gt;&lt;/span&gt;&lt;span style="color:#0000ff;"&gt;&lt;span style="background: SpringGreen;"&gt;=&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;&amp;quot;1.0&amp;quot;&lt;/span&gt;&lt;/span&gt; &lt;span style="color:#ff0000;"&gt;&lt;span style="background: SpringGreen;"&gt;encoding&lt;/span&gt;&lt;/span&gt;&lt;span style="color:#0000ff;"&gt;&lt;span style="background: SpringGreen;"&gt;=&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;&amp;quot;utf-8&amp;quot;&lt;/span&gt;&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;?&lt;/span&gt;&lt;span style="color:#0000ff;"&gt;&lt;span style="background: SpringGreen;"&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;&lt;span style="color:#0000ff;"&gt;&lt;span style="background: SpringGreen;"&gt;&amp;lt;&lt;/span&gt;&lt;/span&gt;&lt;span style="color:#800000;"&gt;&lt;span style="background: SpringGreen;"&gt;hibernate-configuration&lt;/span&gt;&lt;/span&gt; &lt;span style="color:#ff0000;"&gt;&lt;span style="background: SpringGreen;"&gt;xmlns&lt;/span&gt;&lt;/span&gt;&lt;span style="color:#0000ff;"&gt;&lt;span style="background: SpringGreen;"&gt;=&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;&amp;quot;urn:nhibernate-configuration-2.2&amp;quot;&lt;/span&gt;&lt;/span&gt;&lt;span style="color:#0000ff;"&gt;&lt;span style="background: SpringGreen;"&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;  &lt;span style="color:#0000ff;"&gt;&lt;span style="background: SpringGreen;"&gt;&amp;lt;&lt;/span&gt;&lt;/span&gt;&lt;span style="color:#800000;"&gt;&lt;span style="background: SpringGreen;"&gt;session-factory&lt;/span&gt;&lt;/span&gt;&lt;span style="color:#0000ff;"&gt;&lt;span style="background: SpringGreen;"&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;    &lt;span style="color:#0000ff;"&gt;&lt;span style="background: SpringGreen;"&gt;&amp;lt;&lt;/span&gt;&lt;/span&gt;&lt;span style="color:#800000;"&gt;&lt;span style="background: SpringGreen;"&gt;property&lt;/span&gt;&lt;/span&gt; &lt;span style="color:#ff0000;"&gt;&lt;span style="background: SpringGreen;"&gt;name&lt;/span&gt;&lt;/span&gt;&lt;span style="color:#0000ff;"&gt;&lt;span style="background: SpringGreen;"&gt;=&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;&amp;quot;connection.provider&amp;quot;&lt;/span&gt;&lt;/span&gt;&lt;span style="color:#0000ff;"&gt;&lt;span style="background: SpringGreen;"&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;NHibernate.Connection.DriverConnectionProvider&lt;/span&gt;&lt;span style="color:#0000ff;"&gt;&lt;span style="background: SpringGreen;"&gt;&amp;lt;/&lt;/span&gt;&lt;/span&gt;&lt;span style="color:#800000;"&gt;&lt;span style="background: SpringGreen;"&gt;property&lt;/span&gt;&lt;/span&gt;&lt;span style="color:#0000ff;"&gt;&lt;span style="background: SpringGreen;"&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;    &lt;span style="color:#0000ff;"&gt;&lt;span style="background: SpringGreen;"&gt;&amp;lt;&lt;/span&gt;&lt;/span&gt;&lt;span style="color:#800000;"&gt;&lt;span style="background: SpringGreen;"&gt;property&lt;/span&gt;&lt;/span&gt; &lt;span style="color:#ff0000;"&gt;&lt;span style="background: SpringGreen;"&gt;name&lt;/span&gt;&lt;/span&gt;&lt;span style="color:#0000ff;"&gt;&lt;span style="background: SpringGreen;"&gt;=&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;&amp;quot;dialect&amp;quot;&lt;/span&gt;&lt;/span&gt;&lt;span style="color:#0000ff;"&gt;&lt;span style="background: SpringGreen;"&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;NHibernate.Dialect.MsSql2005Dialect&lt;/span&gt;&lt;span style="color:#0000ff;"&gt;&lt;span style="background: SpringGreen;"&gt;&amp;lt;/&lt;/span&gt;&lt;/span&gt;&lt;span style="color:#800000;"&gt;&lt;span style="background: SpringGreen;"&gt;property&lt;/span&gt;&lt;/span&gt;&lt;span style="color:#0000ff;"&gt;&lt;span style="background: SpringGreen;"&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;    &lt;span style="color:#0000ff;"&gt;&lt;span style="background: SpringGreen;"&gt;&amp;lt;&lt;/span&gt;&lt;/span&gt;&lt;span style="color:#800000;"&gt;&lt;span style="background: SpringGreen;"&gt;property&lt;/span&gt;&lt;/span&gt; &lt;span style="color:#ff0000;"&gt;&lt;span style="background: SpringGreen;"&gt;name&lt;/span&gt;&lt;/span&gt;&lt;span style="color:#0000ff;"&gt;&lt;span style="background: SpringGreen;"&gt;=&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;&amp;quot;connection.driver_class&amp;quot;&lt;/span&gt;&lt;/span&gt;&lt;span style="color:#0000ff;"&gt;&lt;span style="background: SpringGreen;"&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;NHibernate.Driver.SqlClientDriver&lt;/span&gt;&lt;span style="color:#0000ff;"&gt;&lt;span style="background: SpringGreen;"&gt;&amp;lt;/&lt;/span&gt;&lt;/span&gt;&lt;span style="color:#800000;"&gt;&lt;span style="background: SpringGreen;"&gt;property&lt;/span&gt;&lt;/span&gt;&lt;span style="color:#0000ff;"&gt;&lt;span style="background: SpringGreen;"&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;    &lt;span style="color:#0000ff;"&gt;&lt;span style="background: SpringGreen;"&gt;&amp;lt;&lt;/span&gt;&lt;/span&gt;&lt;span style="color:#800000;"&gt;&lt;span style="background: SpringGreen;"&gt;property&lt;/span&gt;&lt;/span&gt; &lt;span style="color:#ff0000;"&gt;&lt;span style="background: SpringGreen;"&gt;name&lt;/span&gt;&lt;/span&gt;&lt;span style="color:#0000ff;"&gt;&lt;span style="background: SpringGreen;"&gt;=&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;&amp;quot;connection.connection_string&amp;quot;&lt;/span&gt;&lt;/span&gt;&lt;span style="color:#0000ff;"&gt;&lt;span style="background: SpringGreen;"&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;Server=(local);Database=Test;Integrated&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;Security=SSPI&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;;&lt;/span&gt;&lt;span style="color:#0000ff;"&gt;&lt;span style="background: SpringGreen;"&gt;&amp;lt;/&lt;/span&gt;&lt;/span&gt;&lt;span style="color:#800000;"&gt;&lt;span style="background: SpringGreen;"&gt;property&lt;/span&gt;&lt;/span&gt;&lt;span style="color:#0000ff;"&gt;&lt;span style="background: SpringGreen;"&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;    &lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;    &lt;span style="color:#0000ff;"&gt;&lt;span style="background: SpringGreen;"&gt;&amp;lt;&lt;/span&gt;&lt;/span&gt;&lt;span style="color:#800000;"&gt;&lt;span style="background: SpringGreen;"&gt;property&lt;/span&gt;&lt;/span&gt; &lt;span style="color:#ff0000;"&gt;&lt;span style="background: SpringGreen;"&gt;name&lt;/span&gt;&lt;/span&gt;&lt;span style="color:#0000ff;"&gt;&lt;span style="background: SpringGreen;"&gt;=&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;&amp;quot;show_sql&amp;quot;&lt;/span&gt;&lt;/span&gt;&lt;span style="color:#0000ff;"&gt;&lt;span style="background: SpringGreen;"&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;true&lt;/span&gt;&lt;span style="color:#0000ff;"&gt;&lt;span style="background: SpringGreen;"&gt;&amp;lt;/&lt;/span&gt;&lt;/span&gt;&lt;span style="color:#800000;"&gt;&lt;span style="background: SpringGreen;"&gt;property&lt;/span&gt;&lt;/span&gt;&lt;span style="color:#0000ff;"&gt;&lt;span style="background: SpringGreen;"&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;  &lt;span style="color:#0000ff;"&gt;&lt;span style="background: SpringGreen;"&gt;&amp;lt;/&lt;/span&gt;&lt;/span&gt;&lt;span style="color:#800000;"&gt;&lt;span style="background: SpringGreen;"&gt;session-factory&lt;/span&gt;&lt;/span&gt;&lt;span style="color:#0000ff;"&gt;&lt;span style="background: SpringGreen;"&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;&lt;span style="color:#0000ff;"&gt;&lt;span style="background: SpringGreen;"&gt;&amp;lt;/&lt;/span&gt;&lt;/span&gt;&lt;span style="color:#800000;"&gt;&lt;span style="background: SpringGreen;"&gt;hibernate-configuration&lt;/span&gt;&lt;/span&gt;&lt;span style="color:#0000ff;"&gt;&lt;span style="background: SpringGreen;"&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;&lt;span style="background: SpringGreen;"&gt;The&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;above&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;configuration&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;file&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;assumes&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;that&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;you&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;have&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;an&lt;/span&gt; &lt;b&gt;&lt;span style="background: SpringGreen;"&gt;SQL&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;Server&lt;/span&gt; 
&lt;span style="background: SpringGreen;"&gt;2005&lt;/span&gt;&lt;/b&gt; &lt;span style="background: SpringGreen;"&gt;installed&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;on&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;your&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;local&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;machine&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;and&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;that&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;you&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;are&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;using&lt;/span&gt; 
&lt;b&gt;&lt;span style="background: SpringGreen;"&gt;integrated&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;security&lt;/span&gt;&lt;/b&gt; &lt;span style="background: SpringGreen;"&gt;to&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;authenticate&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;and&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;authorize&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;the&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;access&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;to&lt;/span&gt; 
&lt;span style="background: SpringGreen;"&gt;the&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;database&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;.&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;It&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;further&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;assumes&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;that&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;there&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;exists&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;a&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;database&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;called&lt;/span&gt; 
&lt;b&gt;&lt;span style="background: SpringGreen;"&gt;&amp;#39;&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;Test&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;&amp;#39;&lt;/span&gt;&lt;/b&gt; &lt;span style="background: SpringGreen;"&gt;on&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;this&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;server&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;.&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;To&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;configure&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;NHibernate&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;for&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;other&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;types&lt;/span&gt; 
&lt;span style="background: SpringGreen;"&gt;of&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;databases&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;please&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;consult&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;the&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;online&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;documentation&lt;/span&gt; &lt;a href="http://www.hibernate.org/361.html"&gt;&lt;span style="background: SpringGreen;"&gt;here&lt;/span&gt;&lt;/a&gt;&lt;span style="background: SpringGreen;"&gt;.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="background: SpringGreen;"&gt;Now&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;we&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;define&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;this&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;test&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;method&lt;/span&gt;&lt;/p&gt;
&lt;div&gt;
&lt;div style="border-style:none;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;&lt;span style="background: SpringGreen;"&gt;[&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;Test]&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;&lt;span style="color:#0000ff;"&gt;&lt;span style="background: SpringGreen;"&gt;public&lt;/span&gt;&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;&lt;span style="background: SpringGreen;"&gt;void&lt;/span&gt;&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;Can_configure_NHibernate(&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;)&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;&lt;span style="background: SpringGreen;"&gt;{&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;    &lt;span style="background: SpringGreen;"&gt;var&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;configuration&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;=&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;_&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;factory.Configuration;&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;    &lt;span style="background: SpringGreen;"&gt;Assert.IsNotNull(configuration)&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;;&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;    &lt;span style="background: SpringGreen;"&gt;Assert.AreEqual&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;(&lt;/span&gt;&lt;span style="color:#006080;"&gt;&lt;span style="background: SpringGreen;"&gt;&amp;quot;NHibernate.Connection.DriverConnectionProvider&amp;quot;&lt;/span&gt;&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;,&lt;/span&gt; &lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;                    &lt;span style="background: SpringGreen;"&gt;configuration.Properties&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;[&lt;/span&gt;&lt;span style="color:#006080;"&gt;&lt;span style="background: SpringGreen;"&gt;&amp;quot;connection.provider&amp;quot;&lt;/span&gt;&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;]&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;);&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;    &lt;span style="background: SpringGreen;"&gt;Assert.AreEqual&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;(&lt;/span&gt;&lt;span style="color:#006080;"&gt;&lt;span style="background: SpringGreen;"&gt;&amp;quot;NHibernate.Dialect.MsSql2005Dialect&amp;quot;&lt;/span&gt;&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;,&lt;/span&gt; &lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;                    &lt;span style="background: SpringGreen;"&gt;configuration.Properties&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;[&lt;/span&gt;&lt;span style="color:#006080;"&gt;&lt;span style="background: SpringGreen;"&gt;&amp;quot;dialect&amp;quot;&lt;/span&gt;&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;]&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;);&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;    &lt;span style="background: SpringGreen;"&gt;Assert.AreEqual&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;(&lt;/span&gt;&lt;span style="color:#006080;"&gt;&lt;span style="background: SpringGreen;"&gt;&amp;quot;NHibernate.Driver.SqlClientDriver&amp;quot;&lt;/span&gt;&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;,&lt;/span&gt; &lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;                    &lt;span style="background: SpringGreen;"&gt;configuration.Properties&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;[&lt;/span&gt;&lt;span style="color:#006080;"&gt;&lt;span style="background: SpringGreen;"&gt;&amp;quot;connection.driver_class&amp;quot;&lt;/span&gt;&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;]&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;);&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;    &lt;span style="background: SpringGreen;"&gt;Assert.AreEqual&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;(&lt;/span&gt;&lt;span style="color:#006080;"&gt;&lt;span style="background: SpringGreen;"&gt;&amp;quot;Server=(local);Database=Test;Integrated&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;Security=SSPI&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;;&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;,&lt;/span&gt; &lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;                    &lt;span style="background: SpringGreen;"&gt;configuration.Properties&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;[&lt;/span&gt;&lt;span style="color:#006080;"&gt;&lt;span style="background: SpringGreen;"&gt;&amp;quot;connection.connection_string&amp;quot;&lt;/span&gt;&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;]&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;);&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;&lt;span style="background: SpringGreen;"&gt;}&lt;/span&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;&lt;span style="background: SpringGreen;"&gt;Here&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;we&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;test&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;whether&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;we&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;can&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;successfully&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;create&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;a&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;configuration&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;and&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;whether&lt;/span&gt; 
&lt;span style="background: SpringGreen;"&gt;this&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;configuration&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;contains&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;the&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;attributes&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;we&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;have&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;defined&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;via&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;the&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;NHibernate&lt;/span&gt; 
&lt;span style="background: SpringGreen;"&gt;configuration&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;file&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="background: SpringGreen;"&gt;To&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;fulfill&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;this&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;test&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;we&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;can&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;e.g&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;.&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;implement&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;the&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;following&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;code&lt;/span&gt;&lt;/p&gt;
&lt;div&gt;
&lt;div style="border-style:none;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;&lt;span style="color:#0000ff;"&gt;&lt;span style="background: SpringGreen;"&gt;public&lt;/span&gt;&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;Configuration&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;Configuration&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;&lt;span style="background: SpringGreen;"&gt;{&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;    &lt;span style="background: SpringGreen;"&gt;get&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;    &lt;span style="background: SpringGreen;"&gt;{&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;        &lt;span style="color:#0000ff;"&gt;&lt;span style="background: SpringGreen;"&gt;if&lt;/span&gt;&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;(&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;_configuration&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;=&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;=&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;&lt;span style="background: SpringGreen;"&gt;null&lt;/span&gt;&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;)&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;        &lt;span style="background: SpringGreen;"&gt;{&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;            &lt;span style="background: SpringGreen;"&gt;_&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;configuration&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;=&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;&lt;span style="background: SpringGreen;"&gt;new&lt;/span&gt;&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;Configuration()&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;;&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;            &lt;span style="color:#0000ff;"&gt;&lt;span style="background: SpringGreen;"&gt;string&lt;/span&gt;&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;hibernateConfig&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;=&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;Default_HibernateConfig&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;;&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;            &lt;span style="color:#008000;"&gt;&lt;span style="background: SpringGreen;"&gt;/&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;/if&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;not&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;rooted&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;,&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;assume&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;path&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;from&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;base&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;directory&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;            &lt;span style="color:#0000ff;"&gt;&lt;span style="background: SpringGreen;"&gt;if&lt;/span&gt;&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;(&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;Path.IsPathRooted(hibernateConfig)&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;=&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;=&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;&lt;span style="background: SpringGreen;"&gt;false&lt;/span&gt;&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;)&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;                &lt;span style="background: SpringGreen;"&gt;hibernateConfig&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;=&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;Path.Combine(AppDomain.CurrentDomain.BaseDirectory&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;,&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;hibernateConfig)&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;;&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;            &lt;span style="color:#0000ff;"&gt;&lt;span style="background: SpringGreen;"&gt;if&lt;/span&gt;&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;(&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;File.Exists(hibernateConfig))&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;                &lt;span style="background: SpringGreen;"&gt;_&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;configuration.Configure(&lt;/span&gt;&lt;span style="color:#0000ff;"&gt;&lt;span style="background: SpringGreen;"&gt;new&lt;/span&gt;&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;XmlTextReader(hibernateConfig))&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;;&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;        &lt;span style="background: SpringGreen;"&gt;}&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;        &lt;span style="color:#0000ff;"&gt;&lt;span style="background: SpringGreen;"&gt;return&lt;/span&gt;&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;_&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;configuration;&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;    &lt;span style="background: SpringGreen;"&gt;}&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;&lt;span style="background: SpringGreen;"&gt;}&lt;/span&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;&lt;span style="background: SpringGreen;"&gt;Note&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;that&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;I&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;have&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;defined&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;a&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;class&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;variable&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;_&lt;/span&gt;&lt;b&gt;&lt;span style="background: SpringGreen;"&gt;configuration&lt;/span&gt;&lt;/b&gt; 
&lt;span style="background: SpringGreen;"&gt;such&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;as&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;that&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;I&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;only&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;execute&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;the&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;configuration&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;logic&lt;/span&gt; &lt;i&gt;&lt;span style="background: SpringGreen;"&gt;once&lt;/span&gt;&lt;/i&gt; &lt;span style="background: SpringGreen;"&gt;during&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;the&lt;/span&gt; 
&lt;span style="background: SpringGreen;"&gt;life&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;time&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;of&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;the&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;application&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;.&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;Note&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;further&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;that&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;in&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;this&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;implementation&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;I&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;assume&lt;/span&gt; 
&lt;span style="background: SpringGreen;"&gt;that&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;the&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;configuration&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;of&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;NHibernate&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;is&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;defined&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;via&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;the&lt;/span&gt; 
&lt;b&gt;&lt;span style="background: SpringGreen;"&gt;hibernate.cfg.xml&lt;/span&gt;&lt;/b&gt; &lt;span style="background: SpringGreen;"&gt;file&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;which&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;must&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;be&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;in&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;the&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;same&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;directory&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;as&lt;/span&gt; 
&lt;span style="background: SpringGreen;"&gt;the&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;test&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;assembly&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="background: SpringGreen;"&gt;As&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;soon&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;as&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;I&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;have&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;a&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;valid&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;configuration&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;I&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;can&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;create&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;a&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;NHibernate&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;session&lt;/span&gt; 
&lt;span style="background: SpringGreen;"&gt;factory&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;.&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;Note&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;that&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;this&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;is&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;a&lt;/span&gt; &lt;b&gt;&lt;span style="background: SpringGreen;"&gt;rather&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;expensive&lt;/span&gt;&lt;/b&gt; &lt;span style="background: SpringGreen;"&gt;operation&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;(&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;takes&lt;/span&gt; 
&lt;span style="background: SpringGreen;"&gt;some&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;time&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;depending&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;on&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;the&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;number&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;of&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;entities&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;you&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;are&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;mapping&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;)&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;and&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;thus&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;should&lt;/span&gt; 
&lt;span style="background: SpringGreen;"&gt;only&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;be&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;executed&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;once&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;during&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;the&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;life&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;time&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;of&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;the&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;application&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;.&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;The&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;access&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;to&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;the&lt;/span&gt; 
&lt;span style="background: SpringGreen;"&gt;NHibernate&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;SessionFactory&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;is&lt;/span&gt; &lt;i&gt;&lt;span style="background: SpringGreen;"&gt;thread&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;safe&lt;/span&gt;&lt;/i&gt;&lt;span style="background: SpringGreen;"&gt;!&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="background: SpringGreen;"&gt;Let&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;&amp;#39;&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;s&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;write&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;a&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;test&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;for&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;the&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;creation&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;of&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;the&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;SessionFactory&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;.&lt;/span&gt;&lt;/p&gt;
&lt;div&gt;
&lt;div style="border-style:none;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;&lt;span style="background: SpringGreen;"&gt;[&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;Test]&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;&lt;span style="color:#0000ff;"&gt;&lt;span style="background: SpringGreen;"&gt;public&lt;/span&gt;&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;&lt;span style="background: SpringGreen;"&gt;void&lt;/span&gt;&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;Can_create_and_access_session_factory(&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;)&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;&lt;span style="background: SpringGreen;"&gt;{&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;    &lt;span style="background: SpringGreen;"&gt;var&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;sessionFactory&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;=&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;_&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;factory.SessionFactory;&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;    &lt;span style="background: SpringGreen;"&gt;Assert.IsNotNull(sessionFactory)&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;;&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;    &lt;span style="background: SpringGreen;"&gt;Assert.AreEqual&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;(&lt;/span&gt;&lt;span style="color:#006080;"&gt;&lt;span style="background: SpringGreen;"&gt;&amp;quot;NHibernate.Dialect.MsSql2005Dialect&amp;quot;&lt;/span&gt;&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;,&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;sessionFactory.Dialect.ToString())&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;;&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;&lt;span style="background: SpringGreen;"&gt;}&lt;/span&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;&lt;span style="background: SpringGreen;"&gt;This&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;is&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;a&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;rather&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;basic&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;test&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;and&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;only&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;checks&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;whether&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;I&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;can&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;successfully&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;create&lt;/span&gt; 
&lt;span style="background: SpringGreen;"&gt;a&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;session&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;factory&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;and&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;whether&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;at&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;least&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;one&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;of&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;its&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;properties&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;is&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;configured&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;as&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;I&lt;/span&gt; 
&lt;span style="background: SpringGreen;"&gt;expect&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;it&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;,&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;namely&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;the&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;dialect&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;used&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="background: SpringGreen;"&gt;The&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;implementation&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;to&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;fulfill&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;the&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;test&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;is&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;rather&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;simple&lt;/span&gt;&lt;/p&gt;
&lt;div&gt;
&lt;div style="border-style:none;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;&lt;span style="color:#0000ff;"&gt;&lt;span style="background: SpringGreen;"&gt;public&lt;/span&gt;&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;ISessionFactory&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;SessionFactory&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;&lt;span style="background: SpringGreen;"&gt;{&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;    &lt;span style="background: SpringGreen;"&gt;get&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;    &lt;span style="background: SpringGreen;"&gt;{&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;        &lt;span style="color:#0000ff;"&gt;&lt;span style="background: SpringGreen;"&gt;if&lt;/span&gt;&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;(&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;_sessionFactory&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;=&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;=&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;&lt;span style="background: SpringGreen;"&gt;null&lt;/span&gt;&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;)&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;            &lt;span style="background: SpringGreen;"&gt;_&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;sessionFactory&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;=&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;Configuration.BuildSessionFactory()&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;;&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;        &lt;span style="color:#0000ff;"&gt;&lt;span style="background: SpringGreen;"&gt;return&lt;/span&gt;&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;_&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;sessionFactory;&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;    &lt;span style="background: SpringGreen;"&gt;}&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;&lt;span style="background: SpringGreen;"&gt;}&lt;/span&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;&lt;span style="background: SpringGreen;"&gt;I&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;have&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;defined&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;a&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;class&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;variable&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;_&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;sessionFactory&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;such&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;that&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;I&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;only&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;execute&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;the&lt;/span&gt; 
&lt;span style="background: SpringGreen;"&gt;BuildSessionFactory&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;method&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;once&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;during&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;the&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;life&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;time&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;of&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;the&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;application&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;.&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;The&lt;/span&gt; 
&lt;span style="background: SpringGreen;"&gt;session&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;factory&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;is&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;created&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;on&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;demand&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;,&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;that&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;is&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;when&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;first&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;needed&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;.&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;At&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;the&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;same&lt;/span&gt; 
&lt;span style="background: SpringGreen;"&gt;time&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;this&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;property&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;getter&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;method&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;accesses&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;the&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;previously&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;defined&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;Configuration&lt;/span&gt; 
&lt;span style="background: SpringGreen;"&gt;property&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;which&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;in&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;turn&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;triggers&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;the&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;configuration&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;of&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;NHibernate&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;(&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;if&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;not&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;already&lt;/span&gt; 
&lt;span style="background: SpringGreen;"&gt;done)&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="background: SpringGreen;"&gt;The&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;last&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;missing&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;piece&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;is&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;the&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;implementation&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;of&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;the&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;CreateSession&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;method&lt;/span&gt; 
&lt;span style="background: SpringGreen;"&gt;which&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;now&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;is&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;trivial&lt;/span&gt;&lt;/p&gt;
&lt;div&gt;
&lt;div style="border-style:none;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;&lt;span style="color:#0000ff;"&gt;&lt;span style="background: SpringGreen;"&gt;private&lt;/span&gt;&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;ISession&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;CreateSession(&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;)&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;&lt;span style="background: SpringGreen;"&gt;{&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;    &lt;span style="color:#0000ff;"&gt;&lt;span style="background: SpringGreen;"&gt;return&lt;/span&gt;&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;SessionFactory.OpenSession()&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;;&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;&lt;span style="background: SpringGreen;"&gt;}&lt;/span&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;&lt;span style="background: SpringGreen;"&gt;I&lt;/span&gt; 
&lt;span style="background: SpringGreen;"&gt;want&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;to&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;be&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;able&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;to&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;access&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;the&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;current&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;(&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;open)&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;session&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;via&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;my&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;factory&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;.&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;If&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;there&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;is&lt;/span&gt; 
&lt;span style="background: SpringGreen;"&gt;no&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;such&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;session&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;open&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;at&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;the&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;moment&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;a&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;meaningful&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;exception&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;should&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;be&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;raised&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;.&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;To&lt;/span&gt; 
&lt;span style="background: SpringGreen;"&gt;test&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;this&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;write&lt;/span&gt; 
&lt;/p&gt;
&lt;div&gt;
&lt;div style="border-style:none;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;&lt;span style="background: SpringGreen;"&gt;[&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;Test]&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;&lt;span style="color:#0000ff;"&gt;&lt;span style="background: SpringGreen;"&gt;public&lt;/span&gt;&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;&lt;span style="background: SpringGreen;"&gt;void&lt;/span&gt;&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;Accessing_CurrentSession_when_no_session_open_throws(&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;)&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;&lt;span style="background: SpringGreen;"&gt;{&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;    &lt;span style="color:#0000ff;"&gt;&lt;span style="background: SpringGreen;"&gt;try&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;    &lt;span style="background: SpringGreen;"&gt;{&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;        &lt;span style="background: SpringGreen;"&gt;var&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;session&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;=&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;_&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;factory.CurrentSession;&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;    &lt;span style="background: SpringGreen;"&gt;}&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;    &lt;span style="color:#0000ff;"&gt;&lt;span style="background: SpringGreen;"&gt;catch&lt;/span&gt;&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;(&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;InvalidOperationException)&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;    &lt;span style="background: SpringGreen;"&gt;{&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;}&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;&lt;span style="background: SpringGreen;"&gt;}&lt;/span&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;&lt;span style="background: SpringGreen;"&gt;and&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;the&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;implementation&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;is&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;easy&lt;/span&gt;&lt;/p&gt;
&lt;div&gt;
&lt;div style="border-style:none;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;&lt;span style="color:#0000ff;"&gt;&lt;span style="background: SpringGreen;"&gt;public&lt;/span&gt;&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;ISession&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;CurrentSession&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;&lt;span style="background: SpringGreen;"&gt;{&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;    &lt;span style="background: SpringGreen;"&gt;get&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;    &lt;span style="background: SpringGreen;"&gt;{&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;        &lt;span style="color:#0000ff;"&gt;&lt;span style="background: SpringGreen;"&gt;if&lt;/span&gt;&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;(&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;_currentSession&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;=&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;=&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;&lt;span style="background: SpringGreen;"&gt;null&lt;/span&gt;&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;)&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;            &lt;span style="color:#0000ff;"&gt;&lt;span style="background: SpringGreen;"&gt;throw&lt;/span&gt;&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;&lt;span style="background: SpringGreen;"&gt;new&lt;/span&gt;&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;InvalidOperationException&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;(&lt;/span&gt;&lt;span style="color:#006080;"&gt;&lt;span style="background: SpringGreen;"&gt;&amp;quot;You&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;are&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;not&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;in&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;a&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;unit&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;of&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;work&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;.&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;)&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;;&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;        &lt;span style="color:#0000ff;"&gt;&lt;span style="background: SpringGreen;"&gt;return&lt;/span&gt;&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;_&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;currentSession;&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;    &lt;span style="background: SpringGreen;"&gt;}&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;    &lt;span style="background: SpringGreen;"&gt;set&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;{&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;_&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;currentSession&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;=&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;&lt;span style="background: SpringGreen;"&gt;value&lt;/span&gt;&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;;&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;}&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;&lt;span style="background: SpringGreen;"&gt;}&lt;/span&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;&lt;span style="background: SpringGreen;"&gt;The&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;last&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;method&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;to&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;implement&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;is&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;the&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;UoW&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;disposal&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;method&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;.&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;In&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;this&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;method&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;I&lt;/span&gt; 
&lt;span style="background: SpringGreen;"&gt;want&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;to&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;reset&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;the&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;CurrentSession&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;to&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;null&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;and&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;then&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;forward&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;the&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;call&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;to&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;our&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;static&lt;/span&gt; 
&lt;span style="background: SpringGreen;"&gt;UnitOfWork&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;class&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;(&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;defined&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;in&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;the&lt;/span&gt; &lt;a href="http://blogs.hibernatingrhinos.com/nhibernate/archive/2008/04/10/nhibernate-and-the-unit-of-work-pattern.aspx"&gt;&lt;span style="background: SpringGreen;"&gt;first&lt;/span&gt; 
&lt;span style="background: SpringGreen;"&gt;part&lt;/span&gt;&lt;/a&gt; &lt;span style="background: SpringGreen;"&gt;of&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;this&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;post&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;series&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;)&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;such&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;as&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;that&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;this&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;class&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;can&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;also&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;make&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;an&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;internal&lt;/span&gt; 
&lt;span style="background: SpringGreen;"&gt;clean-up&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;.&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;The&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;implementation&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;might&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;look&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;as&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;follows&lt;/span&gt;&lt;/p&gt;
&lt;div&gt;
&lt;div style="border-style:none;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;&lt;span style="color:#0000ff;"&gt;&lt;span style="background: SpringGreen;"&gt;public&lt;/span&gt;&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;&lt;span style="background: SpringGreen;"&gt;void&lt;/span&gt;&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;DisposeUnitOfWork(UnitOfWorkImplementor&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;adapter&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;)&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;&lt;span style="background: SpringGreen;"&gt;{&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;    &lt;span style="background: SpringGreen;"&gt;CurrentSession&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;=&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;&lt;span style="background: SpringGreen;"&gt;null&lt;/span&gt;&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;;&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;    &lt;span style="background: SpringGreen;"&gt;UnitOfWork.DisposeUnitOfWork(adapter)&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;;&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;&lt;span style="background: SpringGreen;"&gt;}&lt;/span&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;&lt;span style="background: SpringGreen;"&gt;That&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;&amp;#39;&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;s&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;all&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;we&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;have&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;to&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;do&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;for&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;now&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;regarding&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;the&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;UoW&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;factory&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;.&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;Again&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;we&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;have&lt;/span&gt; 
&lt;span style="background: SpringGreen;"&gt;implemented&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;it&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;in&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;a&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;TDD&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;way&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;.&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;When&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;we&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;later&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;re-factor&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;our&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;implementation&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;to&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;make&lt;/span&gt; 
&lt;span style="background: SpringGreen;"&gt;it&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;thread-safe&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;this&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;TDD&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;approach&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;will&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;be&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;a&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;huge&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;benefit&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;since&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;we&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;have&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;a&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;complete&lt;/span&gt; 
&lt;span style="background: SpringGreen;"&gt;test&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;coverage&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;of&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;out&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;code&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;.&lt;/span&gt;&lt;/p&gt;
&lt;h3&gt;&lt;span style="background: SpringGreen;"&gt;The&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;Unit&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;of&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;Work&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;Implementor&lt;/span&gt;&lt;/h3&gt;
&lt;p&gt;&lt;span style="background: SpringGreen;"&gt;This&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;class&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;defines&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;an&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;actual&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;Unit&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;of&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;Work&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;instance&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;.&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;It&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;implements&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;the&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;already&lt;/span&gt; 
&lt;span style="background: SpringGreen;"&gt;mentioned&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;(&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;and&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;defined&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;)&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;interface&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;IUnitOfWork&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;which&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;in&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;turn&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;inherits&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;from&lt;/span&gt; 
&lt;span style="background: SpringGreen;"&gt;IDisposal&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;.&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;This&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;allows&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;us&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;to&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;work&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;with&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;a&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;UoW&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;using&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;the&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;following&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;syntax&lt;/span&gt;&lt;/p&gt;
&lt;div&gt;
&lt;div style="border-style:none;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;&lt;span style="color:#0000ff;"&gt;&lt;span style="background: SpringGreen;"&gt;using&lt;/span&gt;&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;(&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;UnitOfWork.Start())&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;&lt;span style="background: SpringGreen;"&gt;{&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;    &lt;span style="color:#008000;"&gt;&lt;span style="background: SpringGreen;"&gt;/&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;/&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;use&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;Unit&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;of&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;Work&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;&lt;span style="background: SpringGreen;"&gt;}&lt;/span&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;&lt;span style="background: SpringGreen;"&gt;at&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;the&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;end&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;of&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;the&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;block&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;the&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;Dispose&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;method&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;of&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;the&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;UoW&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;will&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;be&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;called&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;.&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;So&lt;/span&gt; 
&lt;span style="background: SpringGreen;"&gt;let&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;&amp;#39;&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;s&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;first&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;think&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;of&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;a&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;test&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;for&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;the&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;implementation&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;of&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;this&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;method&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;.&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;Here&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;we&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;have&lt;/span&gt; 
&lt;span style="background: SpringGreen;"&gt;to&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;use&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;mocking&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;to&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;be&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;able&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;to&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;test&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;our&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;SUT&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;(&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;system&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;under&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;test&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;)&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;in&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;isolation&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;.&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;So&lt;/span&gt; 
&lt;span style="background: SpringGreen;"&gt;let&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;me&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;setup&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;a&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;test&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;fixture&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;first&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;.&lt;/span&gt;&lt;/p&gt;
&lt;div&gt;
&lt;div style="border-style:none;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;&lt;span style="background: SpringGreen;"&gt;[&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;TestFixture]&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;&lt;span style="color:#0000ff;"&gt;&lt;span style="background: SpringGreen;"&gt;public&lt;/span&gt;&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;&lt;span style="background: SpringGreen;"&gt;class&lt;/span&gt;&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;UnitOfWorkImplementor_Fixture&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;&lt;span style="background: SpringGreen;"&gt;{&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;    &lt;span style="color:#0000ff;"&gt;&lt;span style="background: SpringGreen;"&gt;private&lt;/span&gt;&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;&lt;span style="background: SpringGreen;"&gt;readonly&lt;/span&gt;&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;MockRepository&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;_&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;mocks&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;=&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;&lt;span style="background: SpringGreen;"&gt;new&lt;/span&gt;&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;MockRepository()&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;;&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;    &lt;span style="color:#0000ff;"&gt;&lt;span style="background: SpringGreen;"&gt;private&lt;/span&gt;&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;IUnitOfWorkFactory&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;_&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;factory;&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;    &lt;span style="color:#0000ff;"&gt;&lt;span style="background: SpringGreen;"&gt;private&lt;/span&gt;&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;ISession&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;_&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;session;&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;    &lt;span style="color:#0000ff;"&gt;&lt;span style="background: SpringGreen;"&gt;private&lt;/span&gt;&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;IUnitOfWorkImplementor&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;_&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;uow;&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;&amp;nbsp;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;    &lt;span style="background: SpringGreen;"&gt;[&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;SetUp]&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;    &lt;span style="color:#0000ff;"&gt;&lt;span style="background: SpringGreen;"&gt;public&lt;/span&gt;&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;&lt;span style="background: SpringGreen;"&gt;void&lt;/span&gt;&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;SetupContext(&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;)&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;    &lt;span style="background: SpringGreen;"&gt;{&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;        &lt;span style="background: SpringGreen;"&gt;_&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;factory&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;=&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;_&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;mocks.DynamicMock&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;&amp;lt;IUnitOfWorkFactory&amp;gt;();&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;        &lt;span style="background: SpringGreen;"&gt;_&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;session&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;=&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;_&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;mocks.DynamicMock&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;&amp;lt;ISession&amp;gt;();&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;    &lt;span style="background: SpringGreen;"&gt;}&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;&lt;span style="background: SpringGreen;"&gt;}&lt;/span&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;&lt;span style="background: SpringGreen;"&gt;Again&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;I&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;use&lt;/span&gt; &lt;a href="http://www.ayende.com/projects/rhino-mocks.aspx"&gt;&lt;span style="background: SpringGreen;"&gt;Rhino.Mocks&lt;/span&gt;&lt;/a&gt; &lt;span style="background: SpringGreen;"&gt;as&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;my&lt;/span&gt; 
&lt;span style="background: SpringGreen;"&gt;mocking&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;framework&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;.&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;My&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;UoW&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;instance&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;has&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;two&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;external&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;dependencies&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;namely&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;the&lt;/span&gt; 
&lt;span style="background: SpringGreen;"&gt;UnitOfWork&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;factory&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;and&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;the&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;NHibernate&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;session&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;.&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;In&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;the&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;SetupContext&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;I&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;generate&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;a&lt;/span&gt; 
&lt;span style="background: SpringGreen;"&gt;dynamic&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;mock&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;for&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;each&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;of&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;them&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="background: SpringGreen;"&gt;Now&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;I&lt;/span&gt;&amp;nbsp; &lt;span style="background: SpringGreen;"&gt;can&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;write&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;my&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;test&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;method&lt;/span&gt;&lt;/p&gt;
&lt;div&gt;
&lt;div style="border-style:none;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;&lt;span style="background: SpringGreen;"&gt;[&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;Test]&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;&lt;span style="color:#0000ff;"&gt;&lt;span style="background: SpringGreen;"&gt;public&lt;/span&gt;&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;&lt;span style="background: SpringGreen;"&gt;void&lt;/span&gt;&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;Can_Dispose_UnitOfWorkImplementor(&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;)&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;&lt;span style="background: SpringGreen;"&gt;{&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;    &lt;span style="color:#0000ff;"&gt;&lt;span style="background: SpringGreen;"&gt;using&lt;/span&gt;&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;(&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;_mocks.Record())&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;    &lt;span style="background: SpringGreen;"&gt;{&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;        &lt;span style="background: SpringGreen;"&gt;Expect.Call((&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;)&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;=&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;&amp;gt;&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;_&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;factory.DisposeUnitOfWork(&lt;/span&gt;&lt;span style="color:#0000ff;"&gt;&lt;span style="background: SpringGreen;"&gt;null&lt;/span&gt;&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;)&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;).IgnoreArguments();&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;        &lt;span style="background: SpringGreen;"&gt;Expect.Call(_session.Dispose)&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;;&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;    &lt;span style="background: SpringGreen;"&gt;}&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;    &lt;span style="color:#0000ff;"&gt;&lt;span style="background: SpringGreen;"&gt;using&lt;/span&gt;&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;(&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;_mocks.Playback())&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;    &lt;span style="background: SpringGreen;"&gt;{&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;        &lt;span style="background: SpringGreen;"&gt;_&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;uow&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;=&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;&lt;span style="background: SpringGreen;"&gt;new&lt;/span&gt;&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;UnitOfWorkImplementor(_factory&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;,&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;_&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;session);&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;        &lt;span style="background: SpringGreen;"&gt;_&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;uow.Dispose();&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;    &lt;span style="background: SpringGreen;"&gt;}&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;&lt;span style="background: SpringGreen;"&gt;}&lt;/span&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;&lt;span style="background: SpringGreen;"&gt;During&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;the&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;recording&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;phase&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;I&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;define&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;my&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;expectations&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;(&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;of&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;what&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;should&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;happen&lt;/span&gt; 
&lt;span style="background: SpringGreen;"&gt;when&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;calling&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;the&lt;/span&gt; &lt;b&gt;&lt;span style="background: SpringGreen;"&gt;Dispose&lt;/span&gt;&lt;/b&gt; &lt;span style="background: SpringGreen;"&gt;method&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;of&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;the&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;UoW)&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;.&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;First&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;the&lt;/span&gt; 
&lt;b&gt;&lt;span style="background: SpringGreen;"&gt;DisposeUnitOfWork&lt;/span&gt;&lt;/b&gt; &lt;span style="background: SpringGreen;"&gt;method&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;of&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;the&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;factory&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;and&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;second&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;the&lt;/span&gt; 
&lt;b&gt;&lt;span style="background: SpringGreen;"&gt;Dispose&lt;/span&gt;&lt;/b&gt; &lt;span style="background: SpringGreen;"&gt;method&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;of&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;the&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;session&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;object&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;should&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;be&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;called&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="background: SpringGreen;"&gt;Here&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;is&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;the&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;code&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;which&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;fulfills&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;this&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;test&lt;/span&gt;&lt;/p&gt;
&lt;div&gt;
&lt;div style="border-style:none;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;&lt;span style="color:#0000ff;"&gt;&lt;span style="background: SpringGreen;"&gt;public&lt;/span&gt;&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;&lt;span style="background: SpringGreen;"&gt;void&lt;/span&gt;&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;Dispose(&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;)&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;&lt;span style="background: SpringGreen;"&gt;{&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;    &lt;span style="background: SpringGreen;"&gt;_&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;factory.DisposeUnitOfWork(&lt;/span&gt;&lt;span style="color:#0000ff;"&gt;&lt;span style="background: SpringGreen;"&gt;this&lt;/span&gt;&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;)&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;;&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;    &lt;span style="background: SpringGreen;"&gt;_&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;session.Dispose();&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;&lt;span style="background: SpringGreen;"&gt;}&lt;/span&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;&lt;span style="background: SpringGreen;"&gt;As&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;you&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;can&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;see&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;I&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;just&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;forward&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;the&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;call&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;to&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;the&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;Unit&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;of&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;Work&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;factory&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;and&lt;/span&gt; 
&lt;span style="background: SpringGreen;"&gt;dispose&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;my&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;internal&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;(&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;NHibernate)&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;session&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;instance&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;as&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;formulated&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;in&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;the&lt;/span&gt; 
&lt;span style="background: SpringGreen;"&gt;expectations&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;of&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;the&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;test&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="background: SpringGreen;"&gt;When&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;working&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;with&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;a&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;UoW&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;I&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;also&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;have&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;to&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;be&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;able&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;to&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;use&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;transactions&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;.&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;Thus&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;I&lt;/span&gt; 
&lt;span style="background: SpringGreen;"&gt;need&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;a&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;way&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;to&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;&amp;quot;play&amp;quot;&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;with&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;transactions&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;.&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;Let&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;&amp;#39;&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;s&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;call&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;the&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;corresponding&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;methods&lt;/span&gt; 
&lt;b&gt;&lt;span style="background: SpringGreen;"&gt;BeginTransaction&lt;/span&gt;&lt;/b&gt; &lt;span style="background: SpringGreen;"&gt;and&lt;/span&gt; &lt;b&gt;&lt;span style="background: SpringGreen;"&gt;TransactionalFlush&lt;/span&gt;&lt;/b&gt;&lt;span style="background: SpringGreen;"&gt;.&lt;/span&gt;&lt;/p&gt;
&lt;h3&gt;&lt;span style="background: SpringGreen;"&gt;Generic&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;Transaction&lt;/span&gt;&lt;/h3&gt;
&lt;p&gt;&lt;span style="background: SpringGreen;"&gt;To&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;shield&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;the&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;client&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;code&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;from&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;all&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;NHibernate&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;specifics&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;and&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;to&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;provide&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;a&lt;/span&gt; 
&lt;span style="background: SpringGreen;"&gt;simple(r&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;)&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;interface&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;I&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;define&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;a&lt;/span&gt; &lt;b&gt;&lt;span style="background: SpringGreen;"&gt;GenericTransaction&lt;/span&gt;&lt;/b&gt; &lt;span style="background: SpringGreen;"&gt;class&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;(&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;which&lt;/span&gt; 
&lt;span style="background: SpringGreen;"&gt;implements&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;the&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;interface&lt;/span&gt; &lt;b&gt;&lt;span style="background: SpringGreen;"&gt;IGenericTransaction&lt;/span&gt;&lt;/b&gt;&lt;span style="background: SpringGreen;"&gt;)&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;which&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;is&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;just&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;a&lt;/span&gt; 
&lt;span style="background: SpringGreen;"&gt;wrapper&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;around&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;the&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;NHibernate&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;transaction&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;.&lt;/span&gt; &lt;/p&gt;
&lt;p&gt;&lt;span style="background: SpringGreen;"&gt;I&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;think&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;that&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;the&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;implementation&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;is&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;trivial&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;and&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;doesn&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;&amp;#39;&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;t&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;need&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;any&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;further&lt;/span&gt; 
&lt;span style="background: SpringGreen;"&gt;explanation&lt;/span&gt;&lt;/p&gt;
&lt;div&gt;
&lt;div style="border-style:none;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;&lt;span style="color:#0000ff;"&gt;&lt;span style="background: SpringGreen;"&gt;public&lt;/span&gt;&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;&lt;span style="background: SpringGreen;"&gt;interface&lt;/span&gt;&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;IGenericTransaction&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;:&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;IDisposable&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;&lt;span style="background: SpringGreen;"&gt;{&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;    &lt;span style="color:#0000ff;"&gt;&lt;span style="background: SpringGreen;"&gt;void&lt;/span&gt;&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;Commit()&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;;&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;    &lt;span style="color:#0000ff;"&gt;&lt;span style="background: SpringGreen;"&gt;void&lt;/span&gt;&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;Rollback()&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;;&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;&lt;span style="background: SpringGreen;"&gt;}&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;&amp;nbsp;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;&lt;span style="color:#0000ff;"&gt;&lt;span style="background: SpringGreen;"&gt;public&lt;/span&gt;&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;&lt;span style="background: SpringGreen;"&gt;class&lt;/span&gt;&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;GenericTransaction&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;:&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;IGenericTransaction&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;&lt;span style="background: SpringGreen;"&gt;{&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;    &lt;span style="color:#0000ff;"&gt;&lt;span style="background: SpringGreen;"&gt;private&lt;/span&gt;&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;&lt;span style="background: SpringGreen;"&gt;readonly&lt;/span&gt;&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;ITransaction&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;_&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;transaction;&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;&amp;nbsp;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;    &lt;span style="color:#0000ff;"&gt;&lt;span style="background: SpringGreen;"&gt;public&lt;/span&gt;&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;GenericTransaction(ITransaction&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;transaction&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;)&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;    &lt;span style="background: SpringGreen;"&gt;{&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;        &lt;span style="background: SpringGreen;"&gt;_&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;transaction&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;=&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;transaction&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;;&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;    &lt;span style="background: SpringGreen;"&gt;}&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;&amp;nbsp;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;    &lt;span style="color:#0000ff;"&gt;&lt;span style="background: SpringGreen;"&gt;public&lt;/span&gt;&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;&lt;span style="background: SpringGreen;"&gt;void&lt;/span&gt;&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;Commit(&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;)&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;    &lt;span style="background: SpringGreen;"&gt;{&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;        &lt;span style="background: SpringGreen;"&gt;_&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;transaction.Commit();&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;    &lt;span style="background: SpringGreen;"&gt;}&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;&amp;nbsp;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;    &lt;span style="color:#0000ff;"&gt;&lt;span style="background: SpringGreen;"&gt;public&lt;/span&gt;&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;&lt;span style="background: SpringGreen;"&gt;void&lt;/span&gt;&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;Rollback(&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;)&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;    &lt;span style="background: SpringGreen;"&gt;{&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;        &lt;span style="background: SpringGreen;"&gt;_&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;transaction.Rollback();&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;    &lt;span style="background: SpringGreen;"&gt;}&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;&amp;nbsp;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;    &lt;span style="color:#0000ff;"&gt;&lt;span style="background: SpringGreen;"&gt;public&lt;/span&gt;&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;&lt;span style="background: SpringGreen;"&gt;void&lt;/span&gt;&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;Dispose(&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;)&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;    &lt;span style="background: SpringGreen;"&gt;{&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;        &lt;span style="background: SpringGreen;"&gt;_&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;transaction.Dispose();&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;    &lt;span style="background: SpringGreen;"&gt;}&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;&lt;span style="background: SpringGreen;"&gt;}&lt;/span&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;&lt;span style="background: SpringGreen;"&gt;just&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;note&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;that&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;the&lt;/span&gt; &lt;b&gt;&lt;span style="background: SpringGreen;"&gt;IGenericTransaction&lt;/span&gt;&lt;/b&gt; &lt;span style="background: SpringGreen;"&gt;inherits&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;form&lt;/span&gt; 
&lt;b&gt;&lt;span style="background: SpringGreen;"&gt;IDisposable&lt;/span&gt;&lt;/b&gt;&lt;span style="background: SpringGreen;"&gt;.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="background: SpringGreen;"&gt;With&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;this&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;definition&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;of&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;a&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;generic&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;transaction&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;we&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;can&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;proceed&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;to&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;the&lt;/span&gt; 
&lt;span style="background: SpringGreen;"&gt;implementation&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;of&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;the&lt;/span&gt; &lt;b&gt;&lt;span style="background: SpringGreen;"&gt;BeginTransaction&lt;/span&gt;&lt;/b&gt; &lt;span style="background: SpringGreen;"&gt;and&lt;/span&gt; 
&lt;b&gt;&lt;span style="background: SpringGreen;"&gt;TransactionalFlush&lt;/span&gt;&lt;/b&gt; &lt;span style="background: SpringGreen;"&gt;methods&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;.&lt;/span&gt; &lt;/p&gt;
&lt;p&gt;&lt;span style="background: SpringGreen;"&gt;First&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;I&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;&amp;#39;&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;ll&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;implement&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;the&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;BeginTransaction&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;method&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;.&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;As&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;usual&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;I&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;define&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;the&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;test&lt;/span&gt; 
&lt;span style="background: SpringGreen;"&gt;first&lt;/span&gt;&lt;/p&gt;
&lt;div&gt;
&lt;div style="border-style:none;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;&lt;span style="background: SpringGreen;"&gt;[&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;Test]&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;&lt;span style="color:#0000ff;"&gt;&lt;span style="background: SpringGreen;"&gt;public&lt;/span&gt;&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;&lt;span style="background: SpringGreen;"&gt;void&lt;/span&gt;&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;Can_BeginTransaction(&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;)&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;&lt;span style="background: SpringGreen;"&gt;{&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;    &lt;span style="color:#0000ff;"&gt;&lt;span style="background: SpringGreen;"&gt;using&lt;/span&gt;&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;(&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;_mocks.Record())&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;    &lt;span style="background: SpringGreen;"&gt;{&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;        &lt;span style="background: SpringGreen;"&gt;Expect.Call(_session.BeginTransaction()).Return&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;(&lt;/span&gt;&lt;span style="color:#0000ff;"&gt;&lt;span style="background: SpringGreen;"&gt;null&lt;/span&gt;&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;)&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;;&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;    &lt;span style="background: SpringGreen;"&gt;}&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;    &lt;span style="color:#0000ff;"&gt;&lt;span style="background: SpringGreen;"&gt;using&lt;/span&gt;&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;(&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;_mocks.Playback())&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;    &lt;span style="background: SpringGreen;"&gt;{&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;        &lt;span style="background: SpringGreen;"&gt;_&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;uow&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;=&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;&lt;span style="background: SpringGreen;"&gt;new&lt;/span&gt;&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;UnitOfWorkImplementor(_factory&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;,&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;_&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;session);&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;        &lt;span style="background: SpringGreen;"&gt;var&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;transaction&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;=&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;_&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;uow.BeginTransaction();&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;        &lt;span style="background: SpringGreen;"&gt;Assert.IsNotNull(transaction)&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;;&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;    &lt;span style="background: SpringGreen;"&gt;}&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;&lt;span style="background: SpringGreen;"&gt;}&lt;/span&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;&lt;span style="background: SpringGreen;"&gt;I&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;expect&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;that&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;during&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;execution&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;of&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;the&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;method&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;under&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;test&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;the&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;BeginTransaction&lt;/span&gt; 
&lt;span style="background: SpringGreen;"&gt;method&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;of&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;the&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;NHibernate&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;session&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;is&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;called&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;.&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;After&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;calling&lt;/span&gt; 
&lt;b&gt;&lt;span style="background: SpringGreen;"&gt;BeginTransaction&lt;/span&gt;&lt;/b&gt; &lt;span style="background: SpringGreen;"&gt;on&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;the&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;UoW&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;(&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;in&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;the&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;Playback&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;phase&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;)&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;I&lt;/span&gt; 
&lt;span style="background: SpringGreen;"&gt;additionally&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;test&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;whether&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;I&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;get&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;a&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;not-null&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;transaction&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="background: SpringGreen;"&gt;I&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;also&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;want&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;to&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;be&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;able&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;to&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;start&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;a&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;transaction&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;and&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;define&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;an&lt;/span&gt; &lt;a href="http://www.hibernate.org/hib_docs/nhibernate/html/transactions.html"&gt;&lt;span style="background: SpringGreen;"&gt;isolation&lt;/span&gt; 
&lt;span style="background: SpringGreen;"&gt;level&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;for&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;the&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;transaction&lt;/span&gt;&lt;/a&gt;&lt;span style="background: SpringGreen;"&gt;.&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;The&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;corresponding&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;test&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;might&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;look&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;like&lt;/span&gt;&lt;/p&gt;
&lt;div&gt;
&lt;div style="border-style:none;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;&lt;span style="background: SpringGreen;"&gt;[&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;Test]&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;&lt;span style="color:#0000ff;"&gt;&lt;span style="background: SpringGreen;"&gt;public&lt;/span&gt;&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;&lt;span style="background: SpringGreen;"&gt;void&lt;/span&gt;&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;Can_BeginTransaction_specifying_isolation_level(&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;)&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;&lt;span style="background: SpringGreen;"&gt;{&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;    &lt;span style="background: SpringGreen;"&gt;var&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;isolationLevel&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;=&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;IsolationLevel.Serializable&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;;&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;    &lt;span style="color:#0000ff;"&gt;&lt;span style="background: SpringGreen;"&gt;using&lt;/span&gt;&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;(&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;_mocks.Record())&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;    &lt;span style="background: SpringGreen;"&gt;{&lt;/span&gt;   &lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;        &lt;span style="background: SpringGreen;"&gt;Expect.Call(_session.BeginTransaction(isolationLevel)).Return&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;(&lt;/span&gt;&lt;span style="color:#0000ff;"&gt;&lt;span style="background: SpringGreen;"&gt;null&lt;/span&gt;&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;)&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;;&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;    &lt;span style="background: SpringGreen;"&gt;}&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;    &lt;span style="color:#0000ff;"&gt;&lt;span style="background: SpringGreen;"&gt;using&lt;/span&gt;&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;(&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;_mocks.Playback())&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;    &lt;span style="background: SpringGreen;"&gt;{&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;        &lt;span style="background: SpringGreen;"&gt;_&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;uow&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;=&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;&lt;span style="background: SpringGreen;"&gt;new&lt;/span&gt;&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;UnitOfWorkImplementor(_factory&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;,&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;_&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;session);&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;        &lt;span style="background: SpringGreen;"&gt;var&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;transaction&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;=&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;_&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;uow.BeginTransaction(isolationLevel);&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;        &lt;span style="background: SpringGreen;"&gt;Assert.IsNotNull(transaction)&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;;&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;    &lt;span style="background: SpringGreen;"&gt;}&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;&lt;span style="background: SpringGreen;"&gt;}&lt;/span&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;&lt;span style="background: SpringGreen;"&gt;To&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;fulfill&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;the&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;test(s&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;)&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;I&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;just&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;have&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;to&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;create&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;a&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;new&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;instance&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;of&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;a&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;generic&lt;/span&gt; 
&lt;span style="background: SpringGreen;"&gt;transaction&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;and&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;pass&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;the&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;result&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;of&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;the&lt;/span&gt; &lt;i&gt;&lt;span style="background: SpringGreen;"&gt;_&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;session.BeginTransaction&lt;/span&gt;&lt;/i&gt; &lt;span style="background: SpringGreen;"&gt;call&lt;/span&gt; 
&lt;span style="background: SpringGreen;"&gt;to&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;the&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;constructor&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;(&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;that&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;is&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;:&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;a&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;NHibernate&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;ITransaction&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;object&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;)&lt;/span&gt;&lt;/p&gt;
&lt;div&gt;
&lt;div style="border-style:none;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;&lt;span style="color:#0000ff;"&gt;&lt;span style="background: SpringGreen;"&gt;public&lt;/span&gt;&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;IGenericTransaction&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;BeginTransaction(&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;)&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;&lt;span style="background: SpringGreen;"&gt;{&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;    &lt;span style="color:#0000ff;"&gt;&lt;span style="background: SpringGreen;"&gt;return&lt;/span&gt;&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;&lt;span style="background: SpringGreen;"&gt;new&lt;/span&gt;&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;GenericTransaction(_session.BeginTransaction())&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;;&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;&lt;span style="background: SpringGreen;"&gt;}&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;&amp;nbsp;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;&lt;span style="color:#0000ff;"&gt;&lt;span style="background: SpringGreen;"&gt;public&lt;/span&gt;&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;IGenericTransaction&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;BeginTransaction(IsolationLevel&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;isolationLevel&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;)&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;&lt;span style="background: SpringGreen;"&gt;{&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;    &lt;span style="color:#0000ff;"&gt;&lt;span style="background: SpringGreen;"&gt;return&lt;/span&gt;&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;&lt;span style="background: SpringGreen;"&gt;new&lt;/span&gt;&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;GenericTransaction(_session.BeginTransaction(isolationLevel))&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;;&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;&lt;span style="background: SpringGreen;"&gt;}&lt;/span&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;&lt;span style="background: SpringGreen;"&gt;The&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;methods&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;each&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;return&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;me&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;an&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;instance&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;of&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;type&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;GenericTransaction&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;which&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;I&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;can&lt;/span&gt; 
&lt;span style="background: SpringGreen;"&gt;use&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;in&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;my&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;code&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;and&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;call&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;their&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;respective&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;commit&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;or&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;rollback&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;methods&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;if&lt;/span&gt; 
&lt;span style="background: SpringGreen;"&gt;appropriate&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="background: SpringGreen;"&gt;The&lt;/span&gt; &lt;b&gt;&lt;span style="background: SpringGreen;"&gt;TransactionalFlush&lt;/span&gt;&lt;/b&gt; &lt;span style="background: SpringGreen;"&gt;method&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;should&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;flush&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;the&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;content&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;of&lt;/span&gt; 
&lt;span style="background: SpringGreen;"&gt;the&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;NHibernate&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;session&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;to&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;the&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;database&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;wrapped&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;inside&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;a&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;transaction&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;.&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;Let&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;&amp;#39;&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;s&lt;/span&gt; 
&lt;span style="background: SpringGreen;"&gt;define&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;the&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;test(s&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;)&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;for&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;it&lt;/span&gt;&lt;/p&gt;
&lt;div&gt;
&lt;div style="border-style:none;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;&lt;span style="background: SpringGreen;"&gt;[&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;Test]&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;&lt;span style="color:#0000ff;"&gt;&lt;span style="background: SpringGreen;"&gt;public&lt;/span&gt;&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;&lt;span style="background: SpringGreen;"&gt;void&lt;/span&gt;&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;Can_execute_TransactionalFlush(&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;)&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;&lt;span style="background: SpringGreen;"&gt;{&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;    &lt;span style="background: SpringGreen;"&gt;var&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;tx&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;=&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;_&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;mocks.CreateMock&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;&amp;lt;ITransaction&amp;gt;();&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;    &lt;span style="background: SpringGreen;"&gt;var&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;session&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;=&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;_&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;mocks.DynamicMock&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;&amp;lt;ISession&amp;gt;();&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;    &lt;span style="background: SpringGreen;"&gt;SetupResult.For(session.BeginTransaction(IsolationLevel.ReadCommitted)).Return(tx)&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;;&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;&amp;nbsp;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;    &lt;span style="background: SpringGreen;"&gt;_&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;uow&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;=&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;_&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;mocks.PartialMock&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;&amp;lt;UnitOfWorkImplementor&amp;gt;(_factory,&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;_&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;session);&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;&amp;nbsp;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;    &lt;span style="color:#0000ff;"&gt;&lt;span style="background: SpringGreen;"&gt;using&lt;/span&gt;&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;(&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;_mocks.Record())&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;    &lt;span style="background: SpringGreen;"&gt;{&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;        &lt;span style="background: SpringGreen;"&gt;Expect.Call(tx.Commit)&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;;&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;        &lt;span style="background: SpringGreen;"&gt;Expect.Call(tx.Dispose)&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;;&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;    &lt;span style="background: SpringGreen;"&gt;}&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;    &lt;span style="color:#0000ff;"&gt;&lt;span style="background: SpringGreen;"&gt;using&lt;/span&gt;&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;(&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;_mocks.Playback())&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;    &lt;span style="background: SpringGreen;"&gt;{&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;        &lt;span style="background: SpringGreen;"&gt;_&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;uow&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;=&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;&lt;span style="background: SpringGreen;"&gt;new&lt;/span&gt;&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;UnitOfWorkImplementor(_factory&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;,&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;session)&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;;&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;        &lt;span style="background: SpringGreen;"&gt;_&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;uow.TransactionalFlush();&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;    &lt;span style="background: SpringGreen;"&gt;}&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;&lt;span style="background: SpringGreen;"&gt;}&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;&amp;nbsp;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;&lt;span style="background: SpringGreen;"&gt;[&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;Test]&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;&lt;span style="color:#0000ff;"&gt;&lt;span style="background: SpringGreen;"&gt;public&lt;/span&gt;&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;&lt;span style="background: SpringGreen;"&gt;void&lt;/span&gt;&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;Can_execute_TransactionalFlush_specifying_isolation_level(&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;)&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;&lt;span style="background: SpringGreen;"&gt;{&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;    &lt;span style="background: SpringGreen;"&gt;var&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;tx&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;=&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;_&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;mocks.CreateMock&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;&amp;lt;ITransaction&amp;gt;();&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;    &lt;span style="background: SpringGreen;"&gt;var&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;session&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;=&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;_&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;mocks.DynamicMock&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;&amp;lt;ISession&amp;gt;();&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;    &lt;span style="background: SpringGreen;"&gt;SetupResult.For(session.BeginTransaction(IsolationLevel.Serializable)).Return(tx)&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;;&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;&amp;nbsp;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;    &lt;span style="background: SpringGreen;"&gt;_&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;uow&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;=&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;_&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;mocks.PartialMock&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;&amp;lt;UnitOfWorkImplementor&amp;gt;(_factory,&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;session)&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;;&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;&amp;nbsp;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;    &lt;span style="color:#0000ff;"&gt;&lt;span style="background: SpringGreen;"&gt;using&lt;/span&gt;&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;(&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;_mocks.Record())&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;    &lt;span style="background: SpringGreen;"&gt;{&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;        &lt;span style="background: SpringGreen;"&gt;Expect.Call(tx.Commit)&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;;&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;        &lt;span style="background: SpringGreen;"&gt;Expect.Call(tx.Dispose)&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;;&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;    &lt;span style="background: SpringGreen;"&gt;}&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;    &lt;span style="color:#0000ff;"&gt;&lt;span style="background: SpringGreen;"&gt;using&lt;/span&gt;&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;(&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;_mocks.Playback())&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;    &lt;span style="background: SpringGreen;"&gt;{&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;        &lt;span style="background: SpringGreen;"&gt;_&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;uow.TransactionalFlush(IsolationLevel.Serializable);&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;    &lt;span style="background: SpringGreen;"&gt;}&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;&lt;span style="background: SpringGreen;"&gt;}&lt;/span&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;&lt;span style="background: SpringGreen;"&gt;and&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;the&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;implementation&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;is&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;straight&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;forward&lt;/span&gt;&lt;/p&gt;
&lt;div&gt;
&lt;div style="border-style:none;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;&lt;span style="color:#0000ff;"&gt;&lt;span style="background: SpringGreen;"&gt;public&lt;/span&gt;&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;&lt;span style="background: SpringGreen;"&gt;void&lt;/span&gt;&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;TransactionalFlush(&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;)&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;&lt;span style="background: SpringGreen;"&gt;{&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;    &lt;span style="background: SpringGreen;"&gt;TransactionalFlush(IsolationLevel.ReadCommitted)&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;;&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;&lt;span style="background: SpringGreen;"&gt;}&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;&amp;nbsp;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;&lt;span style="color:#0000ff;"&gt;&lt;span style="background: SpringGreen;"&gt;public&lt;/span&gt;&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;&lt;span style="background: SpringGreen;"&gt;void&lt;/span&gt;&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;TransactionalFlush(IsolationLevel&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;isolationLevel&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;)&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;&lt;span style="background: SpringGreen;"&gt;{&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;    &lt;span style="background: SpringGreen;"&gt;IGenericTransaction&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;tx&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;=&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;BeginTransaction(isolationLevel)&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;;&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;    &lt;span style="color:#0000ff;"&gt;&lt;span style="background: SpringGreen;"&gt;try&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;    &lt;span style="background: SpringGreen;"&gt;{&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;        &lt;span style="color:#008000;"&gt;&lt;span style="background: SpringGreen;"&gt;/&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;/forces&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;a&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;flush&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;of&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;the&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;current&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;unit&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;of&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;work&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;        &lt;span style="background: SpringGreen;"&gt;tx.Commit()&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;;&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;    &lt;span style="background: SpringGreen;"&gt;}&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;    &lt;span style="color:#0000ff;"&gt;&lt;span style="background: SpringGreen;"&gt;catch&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;    &lt;span style="background: SpringGreen;"&gt;{&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;        &lt;span style="background: SpringGreen;"&gt;tx.Rollback()&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;;&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;        &lt;span style="color:#0000ff;"&gt;&lt;span style="background: SpringGreen;"&gt;throw&lt;/span&gt;&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;;&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;    &lt;span style="background: SpringGreen;"&gt;}&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;    &lt;span style="color:#0000ff;"&gt;&lt;span style="background: SpringGreen;"&gt;finally&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;    &lt;span style="background: SpringGreen;"&gt;{&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;        &lt;span style="background: SpringGreen;"&gt;tx.Dispose()&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;;&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;    &lt;span style="background: SpringGreen;"&gt;}&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;&lt;span style="background: SpringGreen;"&gt;}&lt;/span&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;&lt;span style="background: SpringGreen;"&gt;Note&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;that&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;when&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;you&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;don&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;&amp;#39;&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;t&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;provide&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;an&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;explicit&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;transaction&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;isolation&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;level&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;our&lt;/span&gt; 
&lt;span style="background: SpringGreen;"&gt;implementation&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;automatically&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;assumes&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;an&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;isolation&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;level&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;equal&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;to&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;&amp;quot;read&lt;/span&gt; 
&lt;span style="background: SpringGreen;"&gt;commited&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;&amp;quot;.&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;Note&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;also&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;that&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;if&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;the&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;Commit&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;of&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;the&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;transaction&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;fails&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;the&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;transaction&lt;/span&gt; 
&lt;span style="background: SpringGreen;"&gt;is&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;rolled&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;back&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;&lt;span style="background: SpringGreen;"&gt;Important&lt;/span&gt;&lt;/b&gt;&lt;span style="background: SpringGreen;"&gt;:&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;In&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;the&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;case&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;of&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;an&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;exception&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;during&lt;/span&gt; 
&lt;b&gt;&lt;span style="background: SpringGreen;"&gt;TransactionalFlush&lt;/span&gt;&lt;/b&gt; &lt;span style="background: SpringGreen;"&gt;do&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;not&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;try&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;to&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;reuse&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;the&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;current&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;unit&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;of&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;work&lt;/span&gt; 
&lt;span style="background: SpringGreen;"&gt;since&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;the&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;session&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;is&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;in&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;an&lt;/span&gt; &lt;a href="http://www.hibernate.org/42.html#A3"&gt;&lt;span style="background: SpringGreen;"&gt;inconsistent&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;state&lt;/span&gt;&lt;/a&gt; &lt;span style="background: SpringGreen;"&gt;and&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;must&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;be&lt;/span&gt; 
&lt;span style="background: SpringGreen;"&gt;closed&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;.&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;Thus&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;abandon&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;this&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;UoW&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;and&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;start&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;a&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;new&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;one&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="background: SpringGreen;"&gt;To&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;increase&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;the&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;usability&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;of&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;the&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;UoW&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;instance&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;a&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;little&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;bit&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;I&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;add&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;the&lt;/span&gt; 
&lt;span style="background: SpringGreen;"&gt;following&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;members&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;(&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;which&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;need&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;no&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;further&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;explanation&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;)&lt;/span&gt;&lt;/p&gt;
&lt;div&gt;
&lt;div style="border-style:none;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;&lt;span style="color:#0000ff;"&gt;&lt;span style="background: SpringGreen;"&gt;public&lt;/span&gt;&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;&lt;span style="background: SpringGreen;"&gt;bool&lt;/span&gt;&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;IsInActiveTransaction&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;&lt;span style="background: SpringGreen;"&gt;{&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;    &lt;span style="background: SpringGreen;"&gt;get&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;    &lt;span style="background: SpringGreen;"&gt;{&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;        &lt;span style="color:#0000ff;"&gt;&lt;span style="background: SpringGreen;"&gt;return&lt;/span&gt;&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;_&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;session.Transaction.IsActive;&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;    &lt;span style="background: SpringGreen;"&gt;}&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;&lt;span style="background: SpringGreen;"&gt;}&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;&amp;nbsp;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;&lt;span style="color:#0000ff;"&gt;&lt;span style="background: SpringGreen;"&gt;public&lt;/span&gt;&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;IUnitOfWorkFactory&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;Factory&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;&lt;span style="background: SpringGreen;"&gt;{&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;    &lt;span style="background: SpringGreen;"&gt;get&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;{&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;&lt;span style="background: SpringGreen;"&gt;return&lt;/span&gt;&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;_&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;factory;&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;}&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;&lt;span style="background: SpringGreen;"&gt;}&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;&amp;nbsp;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;&lt;span style="color:#0000ff;"&gt;&lt;span style="background: SpringGreen;"&gt;public&lt;/span&gt;&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;ISession&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;Session&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;&lt;span style="background: SpringGreen;"&gt;{&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;    &lt;span style="background: SpringGreen;"&gt;get&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;{&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;&lt;span style="background: SpringGreen;"&gt;return&lt;/span&gt;&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;_&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;session;&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;}&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;&lt;span style="background: SpringGreen;"&gt;}&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;&amp;nbsp;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;&lt;span style="color:#0000ff;"&gt;&lt;span style="background: SpringGreen;"&gt;public&lt;/span&gt;&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;&lt;span style="background: SpringGreen;"&gt;void&lt;/span&gt;&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;Flush(&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;)&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;&lt;span style="background: SpringGreen;"&gt;{&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;    &lt;span style="background: SpringGreen;"&gt;_&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;session.Flush();&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;&lt;span style="background: SpringGreen;"&gt;}&lt;/span&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;&lt;span style="background: SpringGreen;"&gt;That&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;&amp;#39;&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;s&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;it&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;!&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;We&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;have&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;now&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;a&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;simple&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;implementation&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;of&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;the&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;Unit&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;of&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;Work&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;pattern&lt;/span&gt; 
&lt;span style="background: SpringGreen;"&gt;for&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;NHibernate&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;.&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;Let&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;me&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;provide&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;an&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;overall&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;picture&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;of&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;our&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;implementation&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="background: SpringGreen;"&gt;&lt;img src="/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/nhibernate.UoW/UoW-overview.png" alt="" /&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;&lt;span style="background: SpringGreen;"&gt;Please&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;remember&lt;/span&gt;&lt;/b&gt;&lt;span style="background: SpringGreen;"&gt;:&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;In&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;this&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;current&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;version&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;the&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;UoW&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;is&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;strictly&lt;/span&gt; 
&lt;span style="background: SpringGreen;"&gt;NOT&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;thread-safe&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;!&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;But&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;I&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;&amp;#39;&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;ll&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;show&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;you&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;how&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;to&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;make&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;it&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;thread-safe&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;in&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;the&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;next&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;post&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;.&lt;/span&gt;&amp;nbsp; 
&lt;/p&gt;
&lt;h2&gt;&lt;span style="background: SpringGreen;"&gt;Using&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;the&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;Unit&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;of&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;Work&lt;/span&gt;&lt;/h2&gt;
&lt;p&gt;&lt;span style="background: SpringGreen;"&gt;In&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;the&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;following&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;section&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;I&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;&amp;#39;&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;ll&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;quickly&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;show&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;the&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;typical&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;usage&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;of&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;the&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;UoW&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;.&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;As&lt;/span&gt; 
&lt;span style="background: SpringGreen;"&gt;usual&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;I&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;do&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;this&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;via&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;TDD&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;.&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;I&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;want&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;to&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;demonstrate&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;how&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;one&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;can&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;define&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;a&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;new&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;instance&lt;/span&gt; 
&lt;span style="background: SpringGreen;"&gt;of&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;an&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;entity&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;and&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;add&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;it&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;to&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;the&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;database&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;.&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;In&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;this&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;case&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;the&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;entity&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;is&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;a&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;simple&lt;/span&gt; 
&lt;span style="background: SpringGreen;"&gt;Person&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;type&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;object&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="background: SpringGreen;"&gt;Let&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;us&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;first&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;set&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;up&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;a&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;test&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;fixture&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;as&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;follows&lt;/span&gt;&lt;/p&gt;
&lt;div&gt;
&lt;div style="border-style:none;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;&lt;span style="color:#0000ff;"&gt;&lt;span style="background: SpringGreen;"&gt;using&lt;/span&gt;&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;System&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;;&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;&lt;span style="color:#0000ff;"&gt;&lt;span style="background: SpringGreen;"&gt;using&lt;/span&gt;&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;System.Reflection&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;;&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;&lt;span style="color:#0000ff;"&gt;&lt;span style="background: SpringGreen;"&gt;using&lt;/span&gt;&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;NHibernate.Tool.hbm2ddl&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;;&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;&lt;span style="color:#0000ff;"&gt;&lt;span style="background: SpringGreen;"&gt;using&lt;/span&gt;&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;NUnit.Framework&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;;&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;&amp;nbsp;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;&lt;span style="color:#0000ff;"&gt;&lt;span style="background: SpringGreen;"&gt;namespace&lt;/span&gt;&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;NHibernateUnitOfWork.Tests&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;&lt;span style="background: SpringGreen;"&gt;{&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;    &lt;span style="background: SpringGreen;"&gt;[&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;TestFixture]&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;    &lt;span style="color:#0000ff;"&gt;&lt;span style="background: SpringGreen;"&gt;public&lt;/span&gt;&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;&lt;span style="background: SpringGreen;"&gt;class&lt;/span&gt;&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;Test_usage_of_UnitOfWork&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;    &lt;span style="background: SpringGreen;"&gt;{&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;        &lt;span style="background: SpringGreen;"&gt;[&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;SetUp]&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;        &lt;span style="color:#0000ff;"&gt;&lt;span style="background: SpringGreen;"&gt;public&lt;/span&gt;&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;&lt;span style="background: SpringGreen;"&gt;void&lt;/span&gt;&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;SetupContext(&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;)&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;        &lt;span style="background: SpringGreen;"&gt;{&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;            &lt;span style="background: SpringGreen;"&gt;UnitOfWork.Configuration.AddAssembly(Assembly.GetExecutingAssembly())&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;;&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;            &lt;span style="color:#0000ff;"&gt;&lt;span style="background: SpringGreen;"&gt;new&lt;/span&gt;&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;SchemaExport(UnitOfWork.Configuration).Execute&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;(&lt;/span&gt;&lt;span style="color:#0000ff;"&gt;&lt;span style="background: SpringGreen;"&gt;false&lt;/span&gt;&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;,&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;&lt;span style="background: SpringGreen;"&gt;true&lt;/span&gt;&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;,&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;&lt;span style="background: SpringGreen;"&gt;false&lt;/span&gt;&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;,&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;&lt;span style="background: SpringGreen;"&gt;false&lt;/span&gt;&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;)&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;;&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;        &lt;span style="background: SpringGreen;"&gt;}&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;    &lt;span style="background: SpringGreen;"&gt;}&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;&lt;span style="background: SpringGreen;"&gt;}&lt;/span&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;&lt;span style="background: SpringGreen;"&gt;In&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;the&lt;/span&gt; &lt;b&gt;&lt;span style="background: SpringGreen;"&gt;SetupContext&lt;/span&gt;&lt;/b&gt; &lt;span style="background: SpringGreen;"&gt;method&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;I&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;first&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;add&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;the&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;current&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;assembly&lt;/span&gt; 
&lt;span style="background: SpringGreen;"&gt;(&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;the&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;one&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;in&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;which&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;this&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;test&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;is&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;running&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;)&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;as&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;a&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;source&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;of&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;the&lt;/span&gt; &lt;i&gt;&lt;span style="background: SpringGreen;"&gt;schema&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;mapping&lt;/span&gt; 
&lt;span style="background: SpringGreen;"&gt;information&lt;/span&gt;&lt;/i&gt; &lt;span style="background: SpringGreen;"&gt;to&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;the&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;configuration&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;of&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;NHibernate&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;(&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;which&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;I&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;can&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;access&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;via&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;our&lt;/span&gt; 
&lt;b&gt;&lt;span style="background: SpringGreen;"&gt;UnitOfWork&lt;/span&gt;&lt;/b&gt; &lt;span style="background: SpringGreen;"&gt;class)&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;.&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;It&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;is&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;important&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;that&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;this&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;call&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;is&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;done&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;prior&lt;/span&gt; 
&lt;span style="background: SpringGreen;"&gt;to&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;the&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;creation&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;of&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;the&lt;/span&gt; &lt;b&gt;&lt;span style="background: SpringGreen;"&gt;SessionFactory&lt;/span&gt;&lt;/b&gt; &lt;span style="background: SpringGreen;"&gt;(&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;that&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;is&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;prior&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;to&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;using&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;a&lt;/span&gt; 
&lt;span style="background: SpringGreen;"&gt;session)&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="background: SpringGreen;"&gt;After&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;extending&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;the&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;configuration&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;I&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;use&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;the&lt;/span&gt; &lt;b&gt;&lt;span style="background: SpringGreen;"&gt;SchemaExport&lt;/span&gt;&lt;/b&gt; 
&lt;span style="background: SpringGreen;"&gt;class&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;of&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;NHibernate&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;to&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;automatically&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;generate&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;the&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;database&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;schema&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;for&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;me&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="background: SpringGreen;"&gt;But&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;wait&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;:&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;up&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;to&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;now&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;I&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;have&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;not&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;defined&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;any&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;schema&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;at&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;all&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;!&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;So&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;let&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;&amp;#39;&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;s&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;do&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;it&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;now&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;.&lt;/span&gt; 
&lt;span style="background: SpringGreen;"&gt;Let&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;&amp;#39;&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;s&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;define&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;a&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;simple&lt;/span&gt; &lt;b&gt;&lt;span style="background: SpringGreen;"&gt;Person&lt;/span&gt;&lt;/b&gt; &lt;span style="background: SpringGreen;"&gt;entity&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;.&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;Add&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;a&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;new&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;file&lt;/span&gt; 
&lt;b&gt;&lt;span style="background: SpringGreen;"&gt;Person.cs&lt;/span&gt;&lt;/b&gt; &lt;span style="background: SpringGreen;"&gt;to&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;the&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;test&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;project&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;and&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;add&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;the&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;following&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;code&lt;/span&gt;&lt;/p&gt;
&lt;div&gt;
&lt;div style="border-style:none;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;&lt;span style="color:#0000ff;"&gt;&lt;span style="background: SpringGreen;"&gt;public&lt;/span&gt;&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;&lt;span style="background: SpringGreen;"&gt;class&lt;/span&gt;&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;Person&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;&lt;span style="background: SpringGreen;"&gt;{&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;    &lt;span style="color:#0000ff;"&gt;&lt;span style="background: SpringGreen;"&gt;public&lt;/span&gt;&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;&lt;span style="background: SpringGreen;"&gt;virtual&lt;/span&gt;&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;Guid&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;Id&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;{&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;get&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;;&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;set&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;;&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;}&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;    &lt;span style="color:#0000ff;"&gt;&lt;span style="background: SpringGreen;"&gt;public&lt;/span&gt;&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;&lt;span style="background: SpringGreen;"&gt;virtual&lt;/span&gt;&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;&lt;span style="background: SpringGreen;"&gt;string&lt;/span&gt;&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;Name&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;{&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;get&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;;&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;set&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;;&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;}&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;    &lt;span style="color:#0000ff;"&gt;&lt;span style="background: SpringGreen;"&gt;public&lt;/span&gt;&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;&lt;span style="background: SpringGreen;"&gt;virtual&lt;/span&gt;&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;DateTime&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;Birthdate&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;{&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;get&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;;&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;set&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;;&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;}&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;&lt;span style="background: SpringGreen;"&gt;}&lt;/span&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;&lt;span style="background: SpringGreen;"&gt;add&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;an&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;XML&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;mapping&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;document&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;called&lt;/span&gt; &lt;b&gt;&lt;span style="background: SpringGreen;"&gt;Person.hbm.xml&lt;/span&gt;&lt;/b&gt; &lt;span style="background: SpringGreen;"&gt;to&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;the&lt;/span&gt; 
&lt;span style="background: SpringGreen;"&gt;test&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;project&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;and&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;define&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;the&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;following&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;content&lt;/span&gt;&lt;/p&gt;
&lt;div&gt;
&lt;div style="border-style:none;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;&lt;span style="color:#0000ff;"&gt;&lt;span style="background: SpringGreen;"&gt;&amp;lt;?&lt;/span&gt;&lt;/span&gt;&lt;span style="color:#800000;"&gt;&lt;span style="background: SpringGreen;"&gt;xml&lt;/span&gt;&lt;/span&gt; &lt;span style="color:#ff0000;"&gt;&lt;span style="background: SpringGreen;"&gt;version&lt;/span&gt;&lt;/span&gt;&lt;span style="color:#0000ff;"&gt;&lt;span style="background: SpringGreen;"&gt;=&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;&amp;quot;1.0&amp;quot;&lt;/span&gt;&lt;/span&gt; &lt;span style="color:#ff0000;"&gt;&lt;span style="background: SpringGreen;"&gt;encoding&lt;/span&gt;&lt;/span&gt;&lt;span style="color:#0000ff;"&gt;&lt;span style="background: SpringGreen;"&gt;=&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;&amp;quot;utf-8&amp;quot;&lt;/span&gt;&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;?&lt;/span&gt;&lt;span style="color:#0000ff;"&gt;&lt;span style="background: SpringGreen;"&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;&lt;span style="color:#0000ff;"&gt;&lt;span style="background: SpringGreen;"&gt;&amp;lt;&lt;/span&gt;&lt;/span&gt;&lt;span style="color:#800000;"&gt;&lt;span style="background: SpringGreen;"&gt;hibernate-mapping&lt;/span&gt;&lt;/span&gt; &lt;span style="color:#ff0000;"&gt;&lt;span style="background: SpringGreen;"&gt;xmlns&lt;/span&gt;&lt;/span&gt;&lt;span style="color:#0000ff;"&gt;&lt;span style="background: SpringGreen;"&gt;=&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;&amp;quot;urn:nhibernate-mapping-2.2&amp;quot;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;                   &lt;span style="color:#ff0000;"&gt;&lt;span style="background: SpringGreen;"&gt;assembly&lt;/span&gt;&lt;/span&gt;&lt;span style="color:#0000ff;"&gt;&lt;span style="background: SpringGreen;"&gt;=&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;&amp;quot;NHibernateUnitOfWork.Tests&amp;quot;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;                   &lt;span style="color:#ff0000;"&gt;&lt;span style="background: SpringGreen;"&gt;namespace&lt;/span&gt;&lt;/span&gt;&lt;span style="color:#0000ff;"&gt;&lt;span style="background: SpringGreen;"&gt;=&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;&amp;quot;NHibernateUnitOfWork.Tests&amp;quot;&lt;/span&gt;&lt;/span&gt;&lt;span style="color:#0000ff;"&gt;&lt;span style="background: SpringGreen;"&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;&amp;nbsp;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;  &lt;span style="color:#0000ff;"&gt;&lt;span style="background: SpringGreen;"&gt;&amp;lt;&lt;/span&gt;&lt;/span&gt;&lt;span style="color:#800000;"&gt;&lt;span style="background: SpringGreen;"&gt;class&lt;/span&gt;&lt;/span&gt; &lt;span style="color:#ff0000;"&gt;&lt;span style="background: SpringGreen;"&gt;name&lt;/span&gt;&lt;/span&gt;&lt;span style="color:#0000ff;"&gt;&lt;span style="background: SpringGreen;"&gt;=&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;&amp;quot;Person&amp;quot;&lt;/span&gt;&lt;/span&gt;&lt;span style="color:#0000ff;"&gt;&lt;span style="background: SpringGreen;"&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;    &lt;span style="color:#0000ff;"&gt;&lt;span style="background: SpringGreen;"&gt;&amp;lt;&lt;/span&gt;&lt;/span&gt;&lt;span style="color:#800000;"&gt;&lt;span style="background: SpringGreen;"&gt;id&lt;/span&gt;&lt;/span&gt; &lt;span style="color:#ff0000;"&gt;&lt;span style="background: SpringGreen;"&gt;name&lt;/span&gt;&lt;/span&gt;&lt;span style="color:#0000ff;"&gt;&lt;span style="background: SpringGreen;"&gt;=&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;&amp;quot;Id&amp;quot;&lt;/span&gt;&lt;/span&gt;&lt;span style="color:#0000ff;"&gt;&lt;span style="background: SpringGreen;"&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;      &lt;span style="color:#0000ff;"&gt;&lt;span style="background: SpringGreen;"&gt;&amp;lt;&lt;/span&gt;&lt;/span&gt;&lt;span style="color:#800000;"&gt;&lt;span style="background: SpringGreen;"&gt;generator&lt;/span&gt;&lt;/span&gt; &lt;span style="color:#ff0000;"&gt;&lt;span style="background: SpringGreen;"&gt;class&lt;/span&gt;&lt;/span&gt;&lt;span style="color:#0000ff;"&gt;&lt;span style="background: SpringGreen;"&gt;=&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;&amp;quot;guid&amp;quot;&lt;/span&gt;&lt;/span&gt;&lt;span style="color:#0000ff;"&gt;&lt;span style="background: SpringGreen;"&gt;/&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;    &lt;span style="color:#0000ff;"&gt;&lt;span style="background: SpringGreen;"&gt;&amp;lt;/&lt;/span&gt;&lt;/span&gt;&lt;span style="color:#800000;"&gt;&lt;span style="background: SpringGreen;"&gt;id&lt;/span&gt;&lt;/span&gt;&lt;span style="color:#0000ff;"&gt;&lt;span style="background: SpringGreen;"&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;    &lt;span style="color:#0000ff;"&gt;&lt;span style="background: SpringGreen;"&gt;&amp;lt;&lt;/span&gt;&lt;/span&gt;&lt;span style="color:#800000;"&gt;&lt;span style="background: SpringGreen;"&gt;property&lt;/span&gt;&lt;/span&gt; &lt;span style="color:#ff0000;"&gt;&lt;span style="background: SpringGreen;"&gt;name&lt;/span&gt;&lt;/span&gt;&lt;span style="color:#0000ff;"&gt;&lt;span style="background: SpringGreen;"&gt;=&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;&amp;quot;Name&amp;quot;&lt;/span&gt;&lt;/span&gt; &lt;span style="color:#ff0000;"&gt;&lt;span style="background: SpringGreen;"&gt;not-null&lt;/span&gt;&lt;/span&gt;&lt;span style="color:#0000ff;"&gt;&lt;span style="background: SpringGreen;"&gt;=&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;&amp;quot;true&amp;quot;&lt;/span&gt;&lt;/span&gt; &lt;span style="color:#ff0000;"&gt;&lt;span style="background: SpringGreen;"&gt;length&lt;/span&gt;&lt;/span&gt;&lt;span style="color:#0000ff;"&gt;&lt;span style="background: SpringGreen;"&gt;=&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;&amp;quot;50&amp;quot;&lt;/span&gt;&lt;/span&gt;&lt;span style="color:#0000ff;"&gt;&lt;span style="background: SpringGreen;"&gt;/&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;    &lt;span style="color:#0000ff;"&gt;&lt;span style="background: SpringGreen;"&gt;&amp;lt;&lt;/span&gt;&lt;/span&gt;&lt;span style="color:#800000;"&gt;&lt;span style="background: SpringGreen;"&gt;property&lt;/span&gt;&lt;/span&gt; &lt;span style="color:#ff0000;"&gt;&lt;span style="background: SpringGreen;"&gt;name&lt;/span&gt;&lt;/span&gt;&lt;span style="color:#0000ff;"&gt;&lt;span style="background: SpringGreen;"&gt;=&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;&amp;quot;Birthdate&amp;quot;&lt;/span&gt;&lt;/span&gt; &lt;span style="color:#ff0000;"&gt;&lt;span style="background: SpringGreen;"&gt;not-null&lt;/span&gt;&lt;/span&gt;&lt;span style="color:#0000ff;"&gt;&lt;span style="background: SpringGreen;"&gt;=&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;&amp;quot;true&amp;quot;&lt;/span&gt;&lt;/span&gt;&lt;span style="color:#0000ff;"&gt;&lt;span style="background: SpringGreen;"&gt;/&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;  &lt;span style="color:#0000ff;"&gt;&lt;span style="background: SpringGreen;"&gt;&amp;lt;/&lt;/span&gt;&lt;/span&gt;&lt;span style="color:#800000;"&gt;&lt;span style="background: SpringGreen;"&gt;class&lt;/span&gt;&lt;/span&gt;&lt;span style="color:#0000ff;"&gt;&lt;span style="background: SpringGreen;"&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;&lt;span style="color:#0000ff;"&gt;&lt;span style="background: SpringGreen;"&gt;&amp;lt;/&lt;/span&gt;&lt;/span&gt;&lt;span style="color:#800000;"&gt;&lt;span style="background: SpringGreen;"&gt;hibernate-mapping&lt;/span&gt;&lt;/span&gt;&lt;span style="color:#0000ff;"&gt;&lt;span style="background: SpringGreen;"&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;&lt;span style="background: SpringGreen;"&gt;Don&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;&amp;#39;&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;t&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;forget&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;to&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;set&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;the&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;&amp;#39;&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;Build&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;Action&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;&amp;#39;&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;property&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;of&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;this&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;item&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;to&lt;/span&gt; 
&lt;b&gt;&lt;span style="background: SpringGreen;"&gt;&amp;#39;&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;Embedded&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;Resource&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;&amp;#39;&lt;/span&gt;&lt;/b&gt;&lt;span style="background: SpringGreen;"&gt;!&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="background: SpringGreen;"&gt;Now&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;we&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;can&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;write&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;a&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;test&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;to&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;insert&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;a&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;new&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;person&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;instance&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;into&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;the&lt;/span&gt; 
&lt;span style="background: SpringGreen;"&gt;database&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;.&lt;/span&gt;&lt;/p&gt;
&lt;div&gt;
&lt;div style="border-style:none;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;&lt;span style="background: SpringGreen;"&gt;[&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;Test]&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;&lt;span style="color:#0000ff;"&gt;&lt;span style="background: SpringGreen;"&gt;public&lt;/span&gt;&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;&lt;span style="background: SpringGreen;"&gt;void&lt;/span&gt;&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;Can_add_a_new_instance_of_an_entity_to_the_database(&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;)&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;&lt;span style="background: SpringGreen;"&gt;{&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;    &lt;span style="color:#0000ff;"&gt;&lt;span style="background: SpringGreen;"&gt;using&lt;/span&gt;&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;(&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;UnitOfWork.Start())&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;    &lt;span style="background: SpringGreen;"&gt;{&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;        &lt;span style="background: SpringGreen;"&gt;var&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;person&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;=&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;&lt;span style="background: SpringGreen;"&gt;new&lt;/span&gt;&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;Person&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;{&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;Name&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;=&lt;/span&gt; &lt;span style="color:#006080;"&gt;&lt;span style="background: SpringGreen;"&gt;&amp;quot;John&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;Doe&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;,&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;Birthdate&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;=&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;&lt;span style="background: SpringGreen;"&gt;new&lt;/span&gt;&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;DateTime(1915&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;,&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;12&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;,&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;15)}&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;;&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;        &lt;span style="background: SpringGreen;"&gt;UnitOfWork.CurrentSession.Save(person)&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;;&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;        &lt;span style="background: SpringGreen;"&gt;UnitOfWork.Current.TransactionalFlush()&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;;&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;    &lt;span style="background: SpringGreen;"&gt;}&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;&lt;span style="background: SpringGreen;"&gt;}&lt;/span&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;&lt;span style="background: SpringGreen;"&gt;When&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;running&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;this&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;test&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;the&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;output&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;generated&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;by&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;NHibernate&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;looks&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;similar&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;to&lt;/span&gt; 
&lt;span style="background: SpringGreen;"&gt;this&lt;/span&gt;&lt;/p&gt;
&lt;div&gt;
&lt;div style="border-style:none;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;&lt;span style="background: SpringGreen;"&gt;NHibernate&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;:&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;INSERT&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;&lt;span style="background: SpringGreen;"&gt;INTO&lt;/span&gt;&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;Person&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;(&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;Name,&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;Birthdate&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;,&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;Id&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;)&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;&lt;span style="background: SpringGreen;"&gt;VALUES&lt;/span&gt;&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;(&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;@p0,&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;@&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;p1,&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;@&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;p2);&lt;/span&gt; &lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;&lt;span style="background: SpringGreen;"&gt;@&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;p0&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;=&lt;/span&gt; &lt;span style="color:#006080;"&gt;&lt;span style="background: SpringGreen;"&gt;&amp;#39;&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;John&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;Doe&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;&amp;#39;&lt;/span&gt;&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;,&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;@&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;p1&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;=&lt;/span&gt; &lt;span style="color:#006080;"&gt;&lt;span style="background: SpringGreen;"&gt;&amp;#39;&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;15.12.1915&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;00:00:00&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;&amp;#39;&lt;/span&gt;&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;,&lt;/span&gt; &lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;&lt;span style="background: SpringGreen;"&gt;@&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;p2&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;=&lt;/span&gt; &lt;span style="color:#006080;"&gt;&lt;span style="background: SpringGreen;"&gt;&amp;#39;&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;bb72ae4c-7d64-4c16-84dc-c0ba2c7d306b&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;&amp;#39;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;h2&gt;&lt;span style="background: SpringGreen;"&gt;Summary&lt;/span&gt;&lt;/h2&gt;
&lt;p&gt;&lt;span style="background: SpringGreen;"&gt;I&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;have&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;shown&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;you&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;a&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;possible&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;implementation&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;of&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;the&lt;/span&gt; &lt;b&gt;&lt;span style="background: SpringGreen;"&gt;Unit&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;of&lt;/span&gt; 
&lt;span style="background: SpringGreen;"&gt;Work&lt;/span&gt;&lt;/b&gt; &lt;span style="background: SpringGreen;"&gt;pattern&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;for&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;NHibernate&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;.&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;The&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;implementation&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;has&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;been&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;developed&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;by&lt;/span&gt; 
&lt;span style="background: SpringGreen;"&gt;using&lt;/span&gt; &lt;a href="http://en.wikipedia.org/wiki/Test-driven_development"&gt;&lt;span style="background: SpringGreen;"&gt;TDD&lt;/span&gt;&lt;/a&gt;&lt;span style="background: SpringGreen;"&gt;.&lt;/span&gt; 
&lt;span style="background: SpringGreen;"&gt;The&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;usage&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;of&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;a&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;Unit&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;of&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;Work&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;pattern&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;simplifies&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;the&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;data&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;manipulation&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;tasks&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;and&lt;/span&gt; 
&lt;span style="background: SpringGreen;"&gt;hides&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;the&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;infrastructure&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;details&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;from&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;the&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;consumer&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;of&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;the&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;UoW&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;.&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;NHibernate&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;offers&lt;/span&gt; 
&lt;span style="background: SpringGreen;"&gt;it&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;&amp;#39;&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;s&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;own&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;implementation&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;of&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;the&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;UoW&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;in&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;the&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;form&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;of&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;the&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;Session&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;object&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;.&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;But&lt;/span&gt; 
&lt;span style="background: SpringGreen;"&gt;NHibernate&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;is&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;just&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;one&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;of&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;several&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;possible&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;ORM&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;tools&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;.&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;With&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;this&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;implementation&lt;/span&gt; 
&lt;span style="background: SpringGreen;"&gt;of&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;the&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;UoW&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;pattern&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;we&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;have&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;hidden&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;most&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;of&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;the&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;specifics&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;of&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;NHibernate&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;an&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;provide&lt;/span&gt; 
&lt;span style="background: SpringGreen;"&gt;a&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;generic&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;interface&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;to&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;the&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;consumer&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;of&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;the&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;UoW&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="background: SpringGreen;"&gt;There&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;are&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;just&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;two&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;open&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;points&lt;/span&gt; &lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;span style="background: SpringGreen;"&gt;our&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;implementation&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;in&lt;/span&gt; &lt;b&gt;&lt;span style="background: SpringGreen;"&gt;not&lt;/span&gt;&lt;/b&gt; &lt;span style="background: SpringGreen;"&gt;thread&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;safe&lt;/span&gt; 
&lt;/li&gt;
&lt;li&gt;&lt;span style="background: SpringGreen;"&gt;we&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;still&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;need&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;to&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;access&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;the&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;session&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;object&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;(&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;through&lt;/span&gt; 
&lt;span style="background: SpringGreen;"&gt;UnitOfWork.CurrentSession&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;)&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;to&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;read&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;or&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;modify&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;our&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;entites&lt;/span&gt; &lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;span style="background: SpringGreen;"&gt;The&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;former&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;I&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;&amp;#39;&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;ll&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;cover&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;in&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;the&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;third&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;part&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;of&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;this&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;article&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;and&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;the&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;latter&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;problem&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;can&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;be&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;solved&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;by&lt;/span&gt; 
&lt;span style="background: SpringGreen;"&gt;introducing&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;a&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;(&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;generic)&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;repository&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;.&lt;/span&gt;&lt;/p&gt;
&lt;h1&gt;&lt;span style="background: SpringGreen;"&gt;Part&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;3&lt;/span&gt;&lt;/h1&gt;
&lt;h2&gt;&lt;span style="background: SpringGreen;"&gt;Introduction&lt;/span&gt;&lt;/h2&gt;
&lt;p&gt;&lt;span style="background: SpringGreen;"&gt;In&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;the&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;previous&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;two&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;chapters&lt;/span&gt;&lt;a href="http://blogs.hibernatingrhinos.com/nhibernate/archive/2008/04/13/nhibernate-and-the-unit-of-work-pattern-part-2.aspx"&gt;&lt;/a&gt; 
&lt;span style="background: SpringGreen;"&gt;I&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;introduced&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;the&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;Unit&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;of&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;Work&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;pattern&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;and&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;developed&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;a&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;working&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;version&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;based&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;on&lt;/span&gt; 
&lt;span style="background: SpringGreen;"&gt;NHibernate&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;.&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;One&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;weak&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;point&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;of&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;the&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;shown&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;implementation&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;is&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;that&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;it&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;is&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;strictly&lt;/span&gt; 
&lt;i&gt;&lt;span style="background: SpringGreen;"&gt;non&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;thread&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;safe&lt;/span&gt;&lt;/i&gt;&lt;span style="background: SpringGreen;"&gt;.&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;In&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;NHibernate&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;the&lt;/span&gt; &lt;b&gt;&lt;span style="background: SpringGreen;"&gt;session&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;object&lt;/span&gt;&lt;/b&gt; 
&lt;span style="background: SpringGreen;"&gt;takes&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;the&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;role&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;of&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;the&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;Unit&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;of&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;Work&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;container&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;.&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;The&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;session&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;object&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;is&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;not&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;thread&lt;/span&gt; 
&lt;span style="background: SpringGreen;"&gt;safe&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;!&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;That&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;is&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;a&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;session&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;instance&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;may&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;not&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;be&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;accessed&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;from&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;different&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;threads&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;.&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;If&lt;/span&gt; 
&lt;span style="background: SpringGreen;"&gt;your&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;application&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;is&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;running&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;on&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;multiple&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;threads&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;(&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;typically&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;an&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;application&lt;/span&gt; 
&lt;span style="background: SpringGreen;"&gt;running&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;on&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;the&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;server&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;)&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;then&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;you&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;have&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;to&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;open&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;a&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;new&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;session&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;instance&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;for&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;each&lt;/span&gt; 
&lt;span style="background: SpringGreen;"&gt;running&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;thread&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;.&lt;/span&gt; &lt;/p&gt;
&lt;p&gt;&lt;span style="background: SpringGreen;"&gt;In&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;this&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;post&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;I&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;want&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;to&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;improve&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;the&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;implementation&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;of&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;the&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;Unit&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;of&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;Work&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;pattern&lt;/span&gt; 
&lt;span style="background: SpringGreen;"&gt;such&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;as&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;that&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;it&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;is&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;thread&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;safe&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;.&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;The&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;class&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;which&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;starts&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;a&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;new&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;unit&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;of&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;work&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;is&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;a&lt;/span&gt; 
&lt;span style="background: SpringGreen;"&gt;static&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;class&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;.&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;All&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;static&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;members&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;of&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;this&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;class&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;are&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;accessible&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;from&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;each&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;thread&lt;/span&gt; 
&lt;span style="background: SpringGreen;"&gt;of&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;the&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;application&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;domain&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;in&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;which&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;your&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;application&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;is&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;running&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;.&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;Now&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;fortunately&lt;/span&gt; 
&lt;span style="background: SpringGreen;"&gt;.&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;NET&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;provides&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;us&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;a&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;mean&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;to&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;define&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;pseudo&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;static&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;fields&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;in&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;a&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;type&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;which&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;are&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;local&lt;/span&gt; 
&lt;span style="background: SpringGreen;"&gt;to&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;a&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;single&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;thread&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;.&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;That&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;is&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;this&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;state&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;is&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;not&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;shared&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;between&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;different&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;threads&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;.&lt;/span&gt; 
&lt;span style="background: SpringGreen;"&gt;Each&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;thread&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;has&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;its&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;own&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;thread&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;static&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;state&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;.&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;To&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;make&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;a&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;field&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;thread&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;static&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;one&lt;/span&gt; 
&lt;span style="background: SpringGreen;"&gt;has&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;to&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;decorate&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;it&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;with&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;the&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;[&lt;/span&gt;&lt;b&gt;&lt;span style="background: SpringGreen;"&gt;ThreadStatic&lt;/span&gt;&lt;/b&gt;&lt;span style="background: SpringGreen;"&gt;]&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;attribute&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;.&lt;/span&gt; &lt;/p&gt;
&lt;p&gt;&lt;span style="background: SpringGreen;"&gt;The&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;easiest&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;and&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;most&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;pragmatic&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;approach&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;would&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;now&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;be&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;to&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;just&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;decorate&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;our&lt;/span&gt; 
&lt;span style="background: SpringGreen;"&gt;_&lt;/span&gt;&lt;b&gt;&lt;span style="background: SpringGreen;"&gt;innerUnitOfWork&lt;/span&gt;&lt;/b&gt; &lt;span style="background: SpringGreen;"&gt;field&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;of&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;the&lt;/span&gt; &lt;b&gt;&lt;span style="background: SpringGreen;"&gt;UnitOfWork&lt;/span&gt; &lt;/b&gt;&lt;span style="background: SpringGreen;"&gt;class&lt;/span&gt; 
&lt;span style="background: SpringGreen;"&gt;with&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;the&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;[&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;ThreadStatic]&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;attribute&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;.&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;But&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;eventually&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;we&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;want&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;to&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;keep&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;additional&lt;/span&gt; 
&lt;span style="background: SpringGreen;"&gt;state&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;in&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;our&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;Unit&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;of&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;Work&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;.&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;Thus&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;we&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;implement&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;a&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;special&lt;/span&gt; &lt;b&gt;&lt;span style="background: SpringGreen;"&gt;Data&lt;/span&gt;&lt;/b&gt; 
&lt;span style="background: SpringGreen;"&gt;class&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;which&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;is&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;a&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;kind&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;of&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;a&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;wrapper&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;around&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;a&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;Hashtable&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;.&lt;/span&gt; &lt;/p&gt;
&lt;h2&gt;&lt;span style="background: SpringGreen;"&gt;Container&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;for&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;Thread&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;Static&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;State&lt;/span&gt;&lt;/h2&gt;
&lt;p&gt;&lt;span style="background: SpringGreen;"&gt;There&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;are&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;2&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;possible&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;scenarios&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;I&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;want&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;to&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;discuss&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;.&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;You&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;either&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;develop&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;an&lt;/span&gt; 
&lt;span style="background: SpringGreen;"&gt;application&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;with&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;a&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;web&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;client&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;or&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;an&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;application&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;with&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;a&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;windows&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;client&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;(&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;e.g.&lt;/span&gt; 
&lt;span style="background: SpringGreen;"&gt;WinForms)&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;.&lt;/span&gt; &lt;/p&gt;
&lt;p&gt;&lt;span style="background: SpringGreen;"&gt;In&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;a&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;web&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;application&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;one&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;has&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;the&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;so&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;called&lt;/span&gt; &lt;b&gt;&lt;span style="background: SpringGreen;"&gt;Http&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;context&lt;/span&gt;&lt;/b&gt; &lt;span style="background: SpringGreen;"&gt;for&lt;/span&gt; 
&lt;span style="background: SpringGreen;"&gt;each&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;request&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;.&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;Multiple&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;requests&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;from&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;different&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;clients&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;can&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;run&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;at&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;the&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;same&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;but&lt;/span&gt; 
&lt;span style="background: SpringGreen;"&gt;each&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;of&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;them&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;runs&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;on&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;a&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;different&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;thread&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;and&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;has&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;it&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;&amp;#39;&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;s&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;own&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;context&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;.&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;In&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;this&lt;/span&gt; 
&lt;span style="background: SpringGreen;"&gt;situation&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;we&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;store&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;the&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;data&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;relevant&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;to&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;the&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;unit&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;of&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;work&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;in&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;the&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;context&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;of&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;the&lt;/span&gt; 
&lt;span style="background: SpringGreen;"&gt;request&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="background: SpringGreen;"&gt;In&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;a&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;windows&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;client&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;application&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;(&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;i.e.&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;Smart&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;Client&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;Application&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;)&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;on&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;the&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;other&lt;/span&gt; 
&lt;span style="background: SpringGreen;"&gt;hand&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;we&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;have&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;a&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;single&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;client&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;that&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;might&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;run&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;on&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;different&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;threads&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;at&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;the&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;same&lt;/span&gt; 
&lt;span style="background: SpringGreen;"&gt;time&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;.&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;In&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;this&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;situation&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;we&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;&amp;quot;attach&amp;quot;&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;the&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;data&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;relevant&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;to&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;the&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;unit&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;of&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;work&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;in&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;so&lt;/span&gt; 
&lt;span style="background: SpringGreen;"&gt;called&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;thread-static&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;fields&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;.&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;A&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;thread-static&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;field&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;is&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;not&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;shared&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;between&lt;/span&gt; 
&lt;span style="background: SpringGreen;"&gt;different&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;threads&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;in&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;the&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;same&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;application&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;.&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;To&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;make&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;a&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;(&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;static)&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;field&lt;/span&gt; 
&lt;span style="background: SpringGreen;"&gt;thread-static&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;we&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;have&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;to&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;just&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;decorate&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;it&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;with&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;a&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;[&lt;/span&gt;&lt;b&gt;&lt;span style="background: SpringGreen;"&gt;ThreadStatic&lt;/span&gt;&lt;/b&gt;&lt;span style="background: SpringGreen;"&gt;]&lt;/span&gt; 
&lt;span style="background: SpringGreen;"&gt;attribute&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="background: SpringGreen;"&gt;In&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;our&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;Unit&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;of&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;Work&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;implementation&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;we&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;have&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;the&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;static&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;UnitOfWork&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;class&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;which&lt;/span&gt; 
&lt;span style="background: SpringGreen;"&gt;contains&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;a&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;static&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;field&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;_&lt;/span&gt;&lt;b&gt;&lt;span style="background: SpringGreen;"&gt;innerUnitOfWork&lt;/span&gt;&lt;/b&gt; &lt;span style="background: SpringGreen;"&gt;of&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;type&lt;/span&gt; 
&lt;b&gt;&lt;span style="background: SpringGreen;"&gt;IUnitOfWork&lt;/span&gt;&lt;/b&gt;&lt;span style="background: SpringGreen;"&gt;.&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;We&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;now&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;need&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;to&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;change&lt;/span&gt; &lt;i&gt;&lt;span style="background: SpringGreen;"&gt;this&lt;/span&gt;&lt;/i&gt; &lt;span style="background: SpringGreen;"&gt;since&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;this&lt;/span&gt; 
&lt;span style="background: SpringGreen;"&gt;kind&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;of&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;implementation&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;is&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;not&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;thread&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;safe&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;.&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;Since&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;we&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;might&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;want&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;to&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;save&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;other&lt;/span&gt; 
&lt;span style="background: SpringGreen;"&gt;data&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;in&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;a&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;thread&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;safe&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;way&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;as&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;well&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;(&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;not&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;just&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;the&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;current&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;instance&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;of&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;the&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;unit&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;of&lt;/span&gt; 
&lt;span style="background: SpringGreen;"&gt;work&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;)&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;we&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;choose&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;a&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;slightly&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;more&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;sophisticated&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;solution&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="background: SpringGreen;"&gt;Let&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;&amp;#39;&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;s&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;define&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;a&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;static&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;class&lt;/span&gt; &lt;b&gt;&lt;span style="background: SpringGreen;"&gt;Local&lt;/span&gt;&lt;/b&gt; &lt;span style="background: SpringGreen;"&gt;which&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;encapsulates&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;the&lt;/span&gt; 
&lt;span style="background: SpringGreen;"&gt;details&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;whether&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;we&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;run&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;a&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;web&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;-&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;or&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;a&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;win-application&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;.&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;This&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;class&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;has&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;just&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;one&lt;/span&gt; 
&lt;span style="background: SpringGreen;"&gt;(&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;static)&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;read-only&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;property&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;Data&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;of&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;type&lt;/span&gt; &lt;b&gt;&lt;span style="background: SpringGreen;"&gt;ILocalData&lt;/span&gt;&lt;/b&gt;&lt;span style="background: SpringGreen;"&gt;.&lt;/span&gt;&lt;/p&gt;
&lt;div&gt;
&lt;div style="border-style:none;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;&lt;span style="color:#0000ff;"&gt;&lt;span style="background: SpringGreen;"&gt;using&lt;/span&gt;&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;System&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;;&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;&lt;span style="color:#0000ff;"&gt;&lt;span style="background: SpringGreen;"&gt;using&lt;/span&gt;&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;System.Collections&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;;&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;&amp;nbsp;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;&lt;span style="color:#0000ff;"&gt;&lt;span style="background: SpringGreen;"&gt;namespace&lt;/span&gt;&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;NHibernateUnitOfWork&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;&lt;span style="background: SpringGreen;"&gt;{&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;    &lt;span style="color:#0000ff;"&gt;&lt;span style="background: SpringGreen;"&gt;public&lt;/span&gt;&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;&lt;span style="background: SpringGreen;"&gt;static&lt;/span&gt;&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;&lt;span style="background: SpringGreen;"&gt;class&lt;/span&gt;&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;Local&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;    &lt;span style="background: SpringGreen;"&gt;{&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;        &lt;span style="color:#0000ff;"&gt;&lt;span style="background: SpringGreen;"&gt;static&lt;/span&gt;&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;&lt;span style="background: SpringGreen;"&gt;readonly&lt;/span&gt;&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;ILocalData&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;_&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;data&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;=&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;&lt;span style="background: SpringGreen;"&gt;new&lt;/span&gt;&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;LocalData()&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;;&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;&amp;nbsp;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;        &lt;span style="color:#0000ff;"&gt;&lt;span style="background: SpringGreen;"&gt;public&lt;/span&gt;&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;&lt;span style="background: SpringGreen;"&gt;static&lt;/span&gt;&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;ILocalData&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;Data&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;        &lt;span style="background: SpringGreen;"&gt;{&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;            &lt;span style="background: SpringGreen;"&gt;get&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;{&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;&lt;span style="background: SpringGreen;"&gt;return&lt;/span&gt;&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;_&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;data;&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;}&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;        &lt;span style="background: SpringGreen;"&gt;}&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;&amp;nbsp;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;        &lt;span style="color:#0000ff;"&gt;&lt;span style="background: SpringGreen;"&gt;private&lt;/span&gt;&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;&lt;span style="background: SpringGreen;"&gt;class&lt;/span&gt;&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;LocalData&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;:&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;ILocalData&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;        &lt;span style="background: SpringGreen;"&gt;{&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;            &lt;span style="color:#008000;"&gt;&lt;span style="background: SpringGreen;"&gt;/&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;/&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;implementation&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;details&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;to&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;de&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;defined&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;        &lt;span style="background: SpringGreen;"&gt;}&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;    &lt;span style="background: SpringGreen;"&gt;}&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;&lt;span style="background: SpringGreen;"&gt;}&lt;/span&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;&lt;span style="background: SpringGreen;"&gt;All&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;details&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;of&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;our&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;implementation&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;are&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;now&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;&amp;quot;hidden&amp;quot;&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;in&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;the&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;class&lt;/span&gt; 
&lt;b&gt;&lt;span style="background: SpringGreen;"&gt;LocalData&lt;/span&gt;&lt;/b&gt; &lt;span style="background: SpringGreen;"&gt;which&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;we&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;choose&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;to&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;be&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;a&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;private&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;child&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;class&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;of&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;the&lt;/span&gt; 
&lt;b&gt;&lt;span style="background: SpringGreen;"&gt;Local&lt;/span&gt;&lt;/b&gt; &lt;span style="background: SpringGreen;"&gt;class&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;.&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;We&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;now&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;want&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;to&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;be&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;able&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;to&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;save&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;into&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;and&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;read&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;data&lt;/span&gt; 
&lt;span style="background: SpringGreen;"&gt;from&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;this&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;local&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;container&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;via&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;a&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;key&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;,&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;e.g&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;.&lt;/span&gt;&lt;/p&gt;
&lt;div&gt;
&lt;div style="border-style:none;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;&lt;span style="background: SpringGreen;"&gt;Local.Data&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;[&lt;/span&gt;&lt;span style="color:#006080;"&gt;&lt;span style="background: SpringGreen;"&gt;&amp;quot;some&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;key&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;]&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;=&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;someValue&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;;&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;&lt;span style="color:#008000;"&gt;&lt;span style="background: SpringGreen;"&gt;/&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;/&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;or&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;&lt;span style="background: SpringGreen;"&gt;otherValue&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;=&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;Local.Data&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;[&lt;/span&gt;&lt;span style="color:#006080;"&gt;&lt;span style="background: SpringGreen;"&gt;&amp;quot;other&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;key&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;]&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;;&lt;/span&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;&lt;span style="background: SpringGreen;"&gt;This&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;should&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;be&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;in&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;a&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;thread&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;safe&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;way&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;.&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;Obviously&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;the&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;above&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;sample&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;client&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;code&lt;/span&gt; 
&lt;span style="background: SpringGreen;"&gt;implies&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;that&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;we&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;use&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;some&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;kind&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;of&lt;/span&gt; &lt;i&gt;&lt;span style="background: SpringGreen;"&gt;dictionary&lt;/span&gt;&lt;/i&gt; &lt;span style="background: SpringGreen;"&gt;to&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;internally&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;store&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;our&lt;/span&gt; 
&lt;span style="background: SpringGreen;"&gt;data&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="background: SpringGreen;"&gt;As&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;usual&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;we&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;formulate&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;our&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;intention&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;in&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;a&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;unit&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;test&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;which&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;might&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;look&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;like&lt;/span&gt; 
&lt;span style="background: SpringGreen;"&gt;this&lt;/span&gt;&lt;/p&gt;
&lt;div&gt;
&lt;div style="border-style:none;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;&lt;span style="color:#0000ff;"&gt;&lt;span style="background: SpringGreen;"&gt;using&lt;/span&gt;&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;System&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;;&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;&lt;span style="color:#0000ff;"&gt;&lt;span style="background: SpringGreen;"&gt;using&lt;/span&gt;&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;NUnit.Framework&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;;&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;&amp;nbsp;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;&lt;span style="color:#0000ff;"&gt;&lt;span style="background: SpringGreen;"&gt;namespace&lt;/span&gt;&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;NHibernateUnitOfWork.Tests&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;&lt;span style="background: SpringGreen;"&gt;{&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;    &lt;span style="background: SpringGreen;"&gt;[&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;TestFixture]&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;    &lt;span style="color:#0000ff;"&gt;&lt;span style="background: SpringGreen;"&gt;public&lt;/span&gt;&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;&lt;span style="background: SpringGreen;"&gt;class&lt;/span&gt;&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;LocalData_Fixture&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;    &lt;span style="background: SpringGreen;"&gt;{&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;        &lt;span style="background: SpringGreen;"&gt;[&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;Test]&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;        &lt;span style="color:#0000ff;"&gt;&lt;span style="background: SpringGreen;"&gt;public&lt;/span&gt;&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;&lt;span style="background: SpringGreen;"&gt;void&lt;/span&gt;&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;Can_store_values_in_local_data(&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;)&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;        &lt;span style="background: SpringGreen;"&gt;{&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;            &lt;span style="background: SpringGreen;"&gt;Local.Data&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;[&lt;/span&gt;&lt;span style="color:#006080;"&gt;&lt;span style="background: SpringGreen;"&gt;&amp;quot;one&amp;quot;&lt;/span&gt;&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;]&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;=&lt;/span&gt; &lt;span style="color:#006080;"&gt;&lt;span style="background: SpringGreen;"&gt;&amp;quot;This&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;is&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;a&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;string&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;;&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;            &lt;span style="background: SpringGreen;"&gt;Local.Data&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;[&lt;/span&gt;&lt;span style="color:#006080;"&gt;&lt;span style="background: SpringGreen;"&gt;&amp;quot;two&amp;quot;&lt;/span&gt;&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;]&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;=&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;99.9m&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;;&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;            &lt;span style="background: SpringGreen;"&gt;var&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;person&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;=&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;&lt;span style="background: SpringGreen;"&gt;new&lt;/span&gt;&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;Person&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;{&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;Name&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;=&lt;/span&gt; &lt;span style="color:#006080;"&gt;&lt;span style="background: SpringGreen;"&gt;&amp;quot;John&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;Doe&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;,&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;Birthdate&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;=&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;&lt;span style="background: SpringGreen;"&gt;new&lt;/span&gt;&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;DateTime(1991&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;,&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;1&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;,&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;15)}&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;;&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;            &lt;span style="background: SpringGreen;"&gt;Local.Data[1&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;]&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;=&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;person&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;;&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;&amp;nbsp;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;            &lt;span style="background: SpringGreen;"&gt;Assert.AreEqual(3&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;,&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;Local.Data.Count)&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;;&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;            &lt;span style="background: SpringGreen;"&gt;Assert.AreEqual&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;(&lt;/span&gt;&lt;span style="color:#006080;"&gt;&lt;span style="background: SpringGreen;"&gt;&amp;quot;This&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;is&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;a&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;string&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;,&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;Local.Data&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;[&lt;/span&gt;&lt;span style="color:#006080;"&gt;&lt;span style="background: SpringGreen;"&gt;&amp;quot;one&amp;quot;&lt;/span&gt;&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;]&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;);&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;            &lt;span style="background: SpringGreen;"&gt;Assert.AreEqual(99.9m&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;,&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;Local.Data&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;[&lt;/span&gt;&lt;span style="color:#006080;"&gt;&lt;span style="background: SpringGreen;"&gt;&amp;quot;two&amp;quot;&lt;/span&gt;&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;]&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;);&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;            &lt;span style="background: SpringGreen;"&gt;Assert.AreSame(person&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;,&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;Local.Data[1])&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;;&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;        &lt;span style="background: SpringGreen;"&gt;}&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;    &lt;span style="background: SpringGreen;"&gt;}&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;&lt;span style="background: SpringGreen;"&gt;}&lt;/span&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;&lt;span style="background: SpringGreen;"&gt;The&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;test&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;shows&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;that&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;I&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;want&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;to&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;be&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;able&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;to&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;not&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;only&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;store&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;basic&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;types&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;but&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;any&lt;/span&gt; 
&lt;span style="background: SpringGreen;"&gt;complex&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;type&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;in&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;my&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;local&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;data&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;container&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;.&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;In&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;this&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;case&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;a&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;string&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;,&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;an&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;integer&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;and&lt;/span&gt; 
&lt;span style="background: SpringGreen;"&gt;an&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;instance&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;of&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;a&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;Person&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;class&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;.&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;The&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;Person&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;class&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;is&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;very&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;basic&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;at&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;looks&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;like&lt;/span&gt; 
&lt;span style="background: SpringGreen;"&gt;follows&lt;/span&gt;&lt;/p&gt;
&lt;div&gt;
&lt;div style="border-style:none;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;&lt;span style="color:#0000ff;"&gt;&lt;span style="background: SpringGreen;"&gt;public&lt;/span&gt;&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;&lt;span style="background: SpringGreen;"&gt;class&lt;/span&gt;&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;Person&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;&lt;span style="background: SpringGreen;"&gt;{&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;    &lt;span style="color:#0000ff;"&gt;&lt;span style="background: SpringGreen;"&gt;public&lt;/span&gt;&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;&lt;span style="background: SpringGreen;"&gt;virtual&lt;/span&gt;&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;Guid&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;Id&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;{&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;get&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;;&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;set&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;;&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;}&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;    &lt;span style="color:#0000ff;"&gt;&lt;span style="background: SpringGreen;"&gt;public&lt;/span&gt;&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;&lt;span style="background: SpringGreen;"&gt;virtual&lt;/span&gt;&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;&lt;span style="background: SpringGreen;"&gt;string&lt;/span&gt;&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;Name&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;{&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;get&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;;&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;set&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;;&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;}&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;    &lt;span style="color:#0000ff;"&gt;&lt;span style="background: SpringGreen;"&gt;public&lt;/span&gt;&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;&lt;span style="background: SpringGreen;"&gt;virtual&lt;/span&gt;&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;DateTime&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;Birthdate&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;{&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;get&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;;&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;set&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;;&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;}&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;&lt;span style="background: SpringGreen;"&gt;}&lt;/span&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;&lt;span style="background: SpringGreen;"&gt;Please&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;also&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;note&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;that&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;I&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;use&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;keys&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;of&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;different&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;type&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;(&lt;/span&gt;&lt;i&gt;&lt;span style="background: SpringGreen;"&gt;string&lt;/span&gt;&lt;/i&gt; &lt;span style="background: SpringGreen;"&gt;and&lt;/span&gt; 
&lt;i&gt;&lt;span style="background: SpringGreen;"&gt;int&lt;/span&gt;&lt;/i&gt;&lt;span style="background: SpringGreen;"&gt;)&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;.&lt;/span&gt; &lt;/p&gt;
&lt;h3&gt;&lt;span style="background: SpringGreen;"&gt;Implementation&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;for&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;Smart&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;Client&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;Applications&lt;/span&gt;&lt;/h3&gt;
&lt;p&gt;&lt;span style="background: SpringGreen;"&gt;Let&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;&amp;#39;&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;s&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;first&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;assume&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;that&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;we&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;want&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;to&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;provide&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;a&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;thread&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;safe&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;unit&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;of&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;work&lt;/span&gt; 
&lt;span style="background: SpringGreen;"&gt;implementation&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;for&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;the&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;smart&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;client&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;application&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;.&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;Then&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;the&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;most&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;basic&lt;/span&gt; 
&lt;span style="background: SpringGreen;"&gt;implementation&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;to&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;fulfill&lt;/span&gt;&amp;nbsp; &lt;span style="background: SpringGreen;"&gt;this&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;test&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;is&lt;/span&gt;&lt;/p&gt;
&lt;div&gt;
&lt;div style="border-style:none;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;&lt;span style="color:#0000ff;"&gt;&lt;span style="background: SpringGreen;"&gt;private&lt;/span&gt;&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;&lt;span style="background: SpringGreen;"&gt;class&lt;/span&gt;&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;LocalData&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;:&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;ILocalData&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;&lt;span style="background: SpringGreen;"&gt;{&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;    &lt;span style="color:#0000ff;"&gt;&lt;span style="background: SpringGreen;"&gt;private&lt;/span&gt;&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;&lt;span style="background: SpringGreen;"&gt;static&lt;/span&gt;&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;Hashtable&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;_&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;localData&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;=&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;new&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;Hashtable()&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;;&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;&amp;nbsp;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;    &lt;span style="color:#0000ff;"&gt;&lt;span style="background: SpringGreen;"&gt;public&lt;/span&gt;&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;&lt;span style="background: SpringGreen;"&gt;object&lt;/span&gt;&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;&lt;span style="background: SpringGreen;"&gt;this&lt;/span&gt;&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;[&lt;/span&gt;&lt;span style="color:#0000ff;"&gt;&lt;span style="background: SpringGreen;"&gt;object&lt;/span&gt;&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;key&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;]&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;    &lt;span style="background: SpringGreen;"&gt;{&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;        &lt;span style="background: SpringGreen;"&gt;get&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;{&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;&lt;span style="background: SpringGreen;"&gt;return&lt;/span&gt;&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;_&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;localData[key];&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;}&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;        &lt;span style="background: SpringGreen;"&gt;set&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;{&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;_&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;localData[key]&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;=&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;&lt;span style="background: SpringGreen;"&gt;value&lt;/span&gt;&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;;&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;}&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;    &lt;span style="background: SpringGreen;"&gt;}&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;&amp;nbsp;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;    &lt;span style="color:#0000ff;"&gt;&lt;span style="background: SpringGreen;"&gt;public&lt;/span&gt;&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;&lt;span style="background: SpringGreen;"&gt;int&lt;/span&gt;&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;Count&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;    &lt;span style="background: SpringGreen;"&gt;{&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;        &lt;span style="background: SpringGreen;"&gt;get&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;{&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;&lt;span style="background: SpringGreen;"&gt;return&lt;/span&gt;&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;_&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;localData.Count;&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;}&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;    &lt;span style="background: SpringGreen;"&gt;}&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;&lt;span style="background: SpringGreen;"&gt;}&lt;/span&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;&lt;span style="background: SpringGreen;"&gt;I&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;just&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;take&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;a&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;hash&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;table&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;as&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;local&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;storage&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;and&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;define&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;an&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;indexer&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;property&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;and&lt;/span&gt; 
&lt;span style="background: SpringGreen;"&gt;a&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;Count&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;property&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;(&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;Note:&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;a&lt;/span&gt; &lt;i&gt;&lt;span style="background: SpringGreen;"&gt;HashTable&lt;/span&gt;&lt;/i&gt; &lt;span style="background: SpringGreen;"&gt;is&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;an&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;often&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;used&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;implementation&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;of&lt;/span&gt; 
&lt;span style="background: SpringGreen;"&gt;a&lt;/span&gt; &lt;i&gt;&lt;span style="background: SpringGreen;"&gt;Dictionary&lt;/span&gt;&lt;/i&gt;&lt;span style="background: SpringGreen;"&gt;)&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="background: SpringGreen;"&gt;We&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;want&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;to&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;also&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;be&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;able&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;to&lt;/span&gt; &lt;b&gt;&lt;span style="background: SpringGreen;"&gt;clear&lt;/span&gt;&lt;/b&gt; &lt;span style="background: SpringGreen;"&gt;the&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;content&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;of&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;the&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;local&lt;/span&gt; 
&lt;span style="background: SpringGreen;"&gt;store&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;and&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;thus&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;we&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;define&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;the&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;following&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;test&lt;/span&gt;&lt;/p&gt;
&lt;div&gt;
&lt;div style="border-style:none;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;&lt;span style="background: SpringGreen;"&gt;[&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;Test]&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;&lt;span style="color:#0000ff;"&gt;&lt;span style="background: SpringGreen;"&gt;public&lt;/span&gt;&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;&lt;span style="background: SpringGreen;"&gt;void&lt;/span&gt;&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;Can_clear_local_data(&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;)&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;&lt;span style="background: SpringGreen;"&gt;{&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;    &lt;span style="background: SpringGreen;"&gt;Local.Data&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;[&lt;/span&gt;&lt;span style="color:#006080;"&gt;&lt;span style="background: SpringGreen;"&gt;&amp;quot;one&amp;quot;&lt;/span&gt;&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;]&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;=&lt;/span&gt; &lt;span style="color:#006080;"&gt;&lt;span style="background: SpringGreen;"&gt;&amp;quot;This&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;is&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;a&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;string&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;;&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;    &lt;span style="background: SpringGreen;"&gt;Local.Data&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;[&lt;/span&gt;&lt;span style="color:#006080;"&gt;&lt;span style="background: SpringGreen;"&gt;&amp;quot;two&amp;quot;&lt;/span&gt;&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;]&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;=&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;99.9m&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;;&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;    &lt;span style="background: SpringGreen;"&gt;Assert.AreEqual(2&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;,&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;Local.Data.Count)&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;;&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;    &lt;span style="background: SpringGreen;"&gt;Local.Data.Clear()&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;;&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;    &lt;span style="background: SpringGreen;"&gt;Assert.AreEqual(0&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;,&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;Local.Data.Count)&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;;&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;&lt;span style="background: SpringGreen;"&gt;}&lt;/span&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;&lt;span style="background: SpringGreen;"&gt;The&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;code&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;to&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;fulfill&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;this&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;test&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;is&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;trivial&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;,&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;just&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;add&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;the&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;code&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;snippet&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;below&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;to&lt;/span&gt; 
&lt;span style="background: SpringGreen;"&gt;the&lt;/span&gt; &lt;b&gt;&lt;span style="background: SpringGreen;"&gt;LocalData&lt;/span&gt;&lt;/b&gt; &lt;span style="background: SpringGreen;"&gt;class&lt;/span&gt;&lt;/p&gt;
&lt;div&gt;
&lt;div style="border-style:none;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;&lt;span style="color:#0000ff;"&gt;&lt;span style="background: SpringGreen;"&gt;public&lt;/span&gt;&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;&lt;span style="background: SpringGreen;"&gt;void&lt;/span&gt;&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;Clear(&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;)&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;&lt;span style="background: SpringGreen;"&gt;{&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;    &lt;span style="background: SpringGreen;"&gt;_&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;localData.Clear();&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;&lt;span style="background: SpringGreen;"&gt;}&lt;/span&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;&lt;span style="background: SpringGreen;"&gt;Unfortunately&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;the&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;test&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;still&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;faults&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;when&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;run&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;!&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;This&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;is&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;because&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;the&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;local&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;data&lt;/span&gt; 
&lt;span style="background: SpringGreen;"&gt;storage&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;is&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;static&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;and&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;all&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;test&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;methods&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;access&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;the&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;same&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;container&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;we&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;have&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;a&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;&amp;quot;side&lt;/span&gt; 
&lt;span style="background: SpringGreen;"&gt;effect&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;&amp;quot;&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;which&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;we&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;must&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;now&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;compensate&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;.&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;We&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;can&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;do&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;it&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;by&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;just&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;clearing&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;the&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;local&lt;/span&gt; 
&lt;span style="background: SpringGreen;"&gt;data&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;container&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;before&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;each&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;test&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;.&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;Add&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;this&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;code&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;to&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;the&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;test&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;fixture&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;class&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;to&lt;/span&gt; 
&lt;span style="background: SpringGreen;"&gt;compensate&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;the&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;side&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;effect&lt;/span&gt;&lt;/p&gt;
&lt;div&gt;
&lt;div style="border-style:none;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;&lt;span style="background: SpringGreen;"&gt;[&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;SetUp]&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;&lt;span style="color:#0000ff;"&gt;&lt;span style="background: SpringGreen;"&gt;public&lt;/span&gt;&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;&lt;span style="background: SpringGreen;"&gt;void&lt;/span&gt;&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;SetupContext(&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;)&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;&lt;span style="background: SpringGreen;"&gt;{&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;    &lt;span style="background: SpringGreen;"&gt;Local.Data.Clear()&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;;&lt;/span&gt;     &lt;span style="color:#008000;"&gt;&lt;span style="background: SpringGreen;"&gt;/&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;/&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;start&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;side-effect&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;free&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;!&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;&lt;span style="background: SpringGreen;"&gt;}&lt;/span&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;&lt;span style="background: SpringGreen;"&gt;Re-run&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;all&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;tests&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;.&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;They&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;should&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;now&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;all&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;pass..&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="background: SpringGreen;"&gt;And&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;now&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;comes&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;the&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;&amp;quot;tricky&amp;quot;&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;part&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;of&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;the&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;implementation&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;where&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;we&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;want&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;to&lt;/span&gt; 
&lt;span style="background: SpringGreen;"&gt;guarantee&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;that&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;our&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;local&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;data&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;store&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;is&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;indeed&lt;/span&gt; &lt;b&gt;&lt;span style="background: SpringGreen;"&gt;thread&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;safe&lt;/span&gt;&lt;/b&gt;&lt;span style="background: SpringGreen;"&gt;.&lt;/span&gt; 
&lt;span style="background: SpringGreen;"&gt;Let&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;&amp;#39;&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;s&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;first&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;define&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;a&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;test&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;for&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;this&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;scenario&lt;/span&gt;&lt;/p&gt;
&lt;div&gt;
&lt;div style="border-style:none;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;&lt;span style="color:#0000ff;"&gt;&lt;span style="background: SpringGreen;"&gt;private&lt;/span&gt;&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;ManualResetEvent&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;_&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;event;&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;&amp;nbsp;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;&lt;span style="background: SpringGreen;"&gt;[&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;Test]&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;&lt;span style="color:#0000ff;"&gt;&lt;span style="background: SpringGreen;"&gt;public&lt;/span&gt;&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;&lt;span style="background: SpringGreen;"&gt;void&lt;/span&gt;&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;Local_data_is_thread_local(&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;)&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;&lt;span style="background: SpringGreen;"&gt;{&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;    &lt;span style="background: SpringGreen;"&gt;Console.WriteLine&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;(&lt;/span&gt;&lt;span style="color:#006080;"&gt;&lt;span style="background: SpringGreen;"&gt;&amp;quot;Starting&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;in&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;main&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;thread&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;{&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;0}&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;,&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;Thread.CurrentThread.ManagedThreadId)&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;;&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;    &lt;span style="background: SpringGreen;"&gt;Local.Data&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;[&lt;/span&gt;&lt;span style="color:#006080;"&gt;&lt;span style="background: SpringGreen;"&gt;&amp;quot;one&amp;quot;&lt;/span&gt;&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;]&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;=&lt;/span&gt; &lt;span style="color:#006080;"&gt;&lt;span style="background: SpringGreen;"&gt;&amp;quot;This&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;is&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;a&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;string&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;;&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;    &lt;span style="background: SpringGreen;"&gt;Assert.AreEqual(1&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;,&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;Local.Data.Count)&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;;&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;&amp;nbsp;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;    &lt;span style="background: SpringGreen;"&gt;_&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;event&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;=&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;&lt;span style="background: SpringGreen;"&gt;new&lt;/span&gt;&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;ManualResetEvent&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;(&lt;/span&gt;&lt;span style="color:#0000ff;"&gt;&lt;span style="background: SpringGreen;"&gt;false&lt;/span&gt;&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;)&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;;&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;    &lt;span style="background: SpringGreen;"&gt;var&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;backgroundThread&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;=&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;&lt;span style="background: SpringGreen;"&gt;new&lt;/span&gt;&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;Thread(RunInOtherThread)&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;;&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;    &lt;span style="background: SpringGreen;"&gt;backgroundThread.Start()&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;;&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;&amp;nbsp;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;    &lt;span style="color:#008000;"&gt;&lt;span style="background: SpringGreen;"&gt;/&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;/&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;give&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;the&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;background&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;thread&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;some&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;time&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;to&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;do&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;its&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;job&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;    &lt;span style="background: SpringGreen;"&gt;Thread.Sleep(100)&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;;&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;    &lt;span style="color:#008000;"&gt;&lt;span style="background: SpringGreen;"&gt;/&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;/&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;we&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;still&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;have&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;only&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;one&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;entry&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;(&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;in&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;this&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;thread&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;)&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;    &lt;span style="background: SpringGreen;"&gt;Assert.AreEqual(1&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;,&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;Local.Data.Count)&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;;&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;&amp;nbsp;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;    &lt;span style="background: SpringGreen;"&gt;Console.WriteLine&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;(&lt;/span&gt;&lt;span style="color:#006080;"&gt;&lt;span style="background: SpringGreen;"&gt;&amp;quot;Signaling&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;background&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;thread&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;from&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;main&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;thread&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;{&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;0}&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;,&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;Thread.CurrentThread.ManagedThreadId)&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;;&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;    &lt;span style="background: SpringGreen;"&gt;_&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;event.Set();&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;    &lt;span style="background: SpringGreen;"&gt;backgroundThread.Join()&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;;&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;&lt;span style="background: SpringGreen;"&gt;}&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;&amp;nbsp;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;&lt;span style="color:#0000ff;"&gt;&lt;span style="background: SpringGreen;"&gt;private&lt;/span&gt;&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;&lt;span style="background: SpringGreen;"&gt;void&lt;/span&gt;&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;RunInOtherThread(&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;)&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;&lt;span style="background: SpringGreen;"&gt;{&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;    &lt;span style="background: SpringGreen;"&gt;Console.WriteLine&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;(&lt;/span&gt;&lt;span style="color:#006080;"&gt;&lt;span style="background: SpringGreen;"&gt;&amp;quot;Starting&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;(&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;background-)&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;thread&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;{&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;0}&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;,&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;Thread.CurrentThread.ManagedThreadId)&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;;&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;    &lt;span style="color:#008000;"&gt;&lt;span style="background: SpringGreen;"&gt;/&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;/&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;initially&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;the&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;local&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;data&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;must&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;be&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;empty&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;for&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;this&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;NEW&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;thread&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;!&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;    &lt;span style="background: SpringGreen;"&gt;Assert.AreEqual(0&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;,&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;Local.Data.Count)&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;;&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;    &lt;span style="background: SpringGreen;"&gt;Local.Data&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;[&lt;/span&gt;&lt;span style="color:#006080;"&gt;&lt;span style="background: SpringGreen;"&gt;&amp;quot;one&amp;quot;&lt;/span&gt;&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;]&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;=&lt;/span&gt; &lt;span style="color:#006080;"&gt;&lt;span style="background: SpringGreen;"&gt;&amp;quot;This&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;is&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;another&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;string&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;;&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;    &lt;span style="background: SpringGreen;"&gt;Assert.AreEqual(1&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;,&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;Local.Data.Count)&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;;&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;&amp;nbsp;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;    &lt;span style="background: SpringGreen;"&gt;Console.WriteLine&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;(&lt;/span&gt;&lt;span style="color:#006080;"&gt;&lt;span style="background: SpringGreen;"&gt;&amp;quot;Waiting&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;on&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;(&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;background-)&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;thread&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;{&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;0}&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;,&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;Thread.CurrentThread.ManagedThreadId)&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;;&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;    &lt;span style="background: SpringGreen;"&gt;_&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;event.WaitOne();&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;    &lt;span style="background: SpringGreen;"&gt;Console.WriteLine&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;(&lt;/span&gt;&lt;span style="color:#006080;"&gt;&lt;span style="background: SpringGreen;"&gt;&amp;quot;Ending&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;(&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;background-)&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;thread&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;{&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;0}&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;,&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;Thread.CurrentThread.ManagedThreadId)&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;;&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;&lt;span style="background: SpringGreen;"&gt;}&lt;/span&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;&lt;span style="background: SpringGreen;"&gt;In&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;the&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;above&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;code&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;I&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;run&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;two&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;threads&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;in&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;parallel&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;,&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;the&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;thread&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;on&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;which&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;the&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;test&lt;/span&gt; 
&lt;span style="background: SpringGreen;"&gt;is&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;running&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;(&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;let&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;&amp;#39;&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;s&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;call&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;it&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;the&lt;/span&gt; &lt;b&gt;&lt;span style="background: SpringGreen;"&gt;main&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;thread&lt;/span&gt;&lt;/b&gt;&lt;span style="background: SpringGreen;"&gt;)&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;and&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;an&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;additional&lt;/span&gt; 
&lt;b&gt;&lt;span style="background: SpringGreen;"&gt;background&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;thread&lt;/span&gt;&lt;/b&gt;&lt;span style="background: SpringGreen;"&gt;.&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;The&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;code&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;which&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;is&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;executed&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;in&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;the&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;background&lt;/span&gt; 
&lt;span style="background: SpringGreen;"&gt;thread&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;is&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;implemented&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;in&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;the&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;helper&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;method&lt;/span&gt; &lt;b&gt;&lt;span style="background: SpringGreen;"&gt;RunInOtherThread&lt;/span&gt;&lt;/b&gt;&lt;span style="background: SpringGreen;"&gt;.&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;To&lt;/span&gt; 
&lt;span style="background: SpringGreen;"&gt;be&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;able&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;to&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;synchronize&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;the&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;two&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;threads&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;I&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;use&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;an&lt;/span&gt; &lt;b&gt;&lt;span style="background: SpringGreen;"&gt;Event&lt;/span&gt;&lt;/b&gt;&lt;span style="background: SpringGreen;"&gt;,&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;in&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;this&lt;/span&gt; 
&lt;span style="background: SpringGreen;"&gt;case&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;a&lt;/span&gt; &lt;b&gt;&lt;span style="background: SpringGreen;"&gt;ManualResetEvent&lt;/span&gt;&lt;/b&gt;&lt;span style="background: SpringGreen;"&gt;.&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;I&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;have&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;put&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;some&lt;/span&gt; 
&lt;i&gt;&lt;span style="background: SpringGreen;"&gt;Console.WriteLine&lt;/span&gt;&lt;/i&gt; &lt;span style="background: SpringGreen;"&gt;statements&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;in&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;the&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;code&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;for&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;debugging&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;purposes&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="background: SpringGreen;"&gt;In&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;the&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;main&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;thread&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;I&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;add&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;some&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;data&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;to&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;the&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;local&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;data&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;store&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;.&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;Then&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;I&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;spin&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;up&lt;/span&gt; 
&lt;span style="background: SpringGreen;"&gt;the&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;background&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;thread&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;.&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;In&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;the&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;background&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;thread&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;I&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;first&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;test&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;that&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;my&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;(&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;thread-)&lt;/span&gt; 
&lt;span style="background: SpringGreen;"&gt;local&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;data&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;store&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;is&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;empty&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;and&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;then&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;also&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;fill&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;in&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;some&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;data&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;.&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;With&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;the&lt;/span&gt; 
&lt;b&gt;&lt;span style="background: SpringGreen;"&gt;Assert&lt;/span&gt;&lt;/b&gt; &lt;span style="background: SpringGreen;"&gt;statements&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;I&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;test&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;that&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;we&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;really&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;have&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;a&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;thread&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;safe&lt;/span&gt; 
&lt;span style="background: SpringGreen;"&gt;behavior&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="background: SpringGreen;"&gt;The&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;only&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;change&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;needed&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;to&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;make&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;my&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;implementation&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;thread&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;safe&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;is&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;to&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;decorate&lt;/span&gt; 
&lt;span style="background: SpringGreen;"&gt;the&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;static&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;field&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;_&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;localData&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;with&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;the&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;[&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;ThreadStatic]&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;attribute&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;.&lt;/span&gt;&lt;/p&gt;
&lt;div&gt;
&lt;div style="border-style:none;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;&lt;span style="background: SpringGreen;"&gt;[&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;ThreadStatic]&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;&lt;span style="color:#0000ff;"&gt;&lt;span style="background: SpringGreen;"&gt;private&lt;/span&gt;&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;&lt;span style="background: SpringGreen;"&gt;static&lt;/span&gt;&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;Hashtable&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;_&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;localData&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;=&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;&lt;span style="background: SpringGreen;"&gt;new&lt;/span&gt;&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;Hashtable()&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;;&lt;/span&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;&lt;span style="background: SpringGreen;"&gt;When&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;the&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;test&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;is&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;run&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;it&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;should&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;pass&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;and&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;produce&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;an&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;output&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;similar&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;to&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;this&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="background: SpringGreen;"&gt;&lt;img src="/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/nhibernate.UoW/UoW-Multi_2D00_Threading-UnitTest.png" alt="" /&gt;&lt;/span&gt;&lt;/p&gt;
&lt;h3&gt;&lt;span style="background: SpringGreen;"&gt;Implementation&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;for&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;Web&lt;/span&gt;&lt;/h3&gt;
&lt;p&gt;&lt;span style="background: SpringGreen;"&gt;As&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;mentioned&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;above&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;in&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;this&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;scenario&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;we&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;want&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;to&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;store&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;our&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;local&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;data&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;in&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;the&lt;/span&gt; 
&lt;span style="background: SpringGreen;"&gt;context&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;of&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;the&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;current&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;HTTP&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;request&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;.&lt;/span&gt; &lt;/p&gt;
&lt;p&gt;&lt;span style="background: SpringGreen;"&gt;First&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;I&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;want&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;to&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;provide&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;an&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;indicator&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;whether&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;I&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;am&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;running&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;in&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;web&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;and&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;thus&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;I&lt;/span&gt; 
&lt;span style="background: SpringGreen;"&gt;add&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;the&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;following&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;to&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;the&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;code&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;snippet&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;to&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;the&lt;/span&gt; &lt;b&gt;&lt;span style="background: SpringGreen;"&gt;LocalData&lt;/span&gt;&lt;/b&gt; 
&lt;span style="background: SpringGreen;"&gt;class&lt;/span&gt;&lt;/p&gt;
&lt;div&gt;
&lt;div style="border-style:none;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;&lt;span style="color:#0000ff;"&gt;&lt;span style="background: SpringGreen;"&gt;public&lt;/span&gt;&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;&lt;span style="background: SpringGreen;"&gt;static&lt;/span&gt;&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;&lt;span style="background: SpringGreen;"&gt;bool&lt;/span&gt;&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;RunningInWeb&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;&lt;span style="background: SpringGreen;"&gt;{&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;    &lt;span style="background: SpringGreen;"&gt;get&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;{&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;&lt;span style="background: SpringGreen;"&gt;return&lt;/span&gt;&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;HttpContext.Current&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;!&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;=&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;&lt;span style="background: SpringGreen;"&gt;null&lt;/span&gt;&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;;&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;}&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;&lt;span style="background: SpringGreen;"&gt;}&lt;/span&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;&lt;span style="background: SpringGreen;"&gt;Here&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;I&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;use&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;the&lt;/span&gt; &lt;b&gt;&lt;span style="background: SpringGreen;"&gt;HttpContext&lt;/span&gt;&lt;/b&gt; &lt;span style="background: SpringGreen;"&gt;class&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;of&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;the&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;.&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;NET&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;framework&lt;/span&gt; 
&lt;span style="background: SpringGreen;"&gt;(&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;namespace&lt;/span&gt; &lt;i&gt;&lt;span style="background: SpringGreen;"&gt;System.Web&lt;/span&gt;&lt;/i&gt;&lt;span style="background: SpringGreen;"&gt;)&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;.&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;It&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;&amp;#39;&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;s&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;static&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;property&lt;/span&gt; &lt;b&gt;&lt;span style="background: SpringGreen;"&gt;Current&lt;/span&gt;&lt;/b&gt; 
&lt;span style="background: SpringGreen;"&gt;is&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;equal&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;to&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;null&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;if&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;we&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;do&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;not&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;run&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;in&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;the&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;context&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;of&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;a&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;web&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;application&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="background: SpringGreen;"&gt;To&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;abstract&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;the&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;details&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;of&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;the&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;context&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;(&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;web-&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;or&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;smart&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;client&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;application&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;)&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;I&lt;/span&gt; 
&lt;span style="background: SpringGreen;"&gt;define&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;a&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;private&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;read-only&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;property&lt;/span&gt; &lt;b&gt;&lt;span style="background: SpringGreen;"&gt;LocalHashtable&lt;/span&gt;&lt;/b&gt; &lt;span style="background: SpringGreen;"&gt;as&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;below&lt;/span&gt;&lt;/p&gt;
&lt;div&gt;
&lt;div style="border-style:none;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;&lt;span style="color:#0000ff;"&gt;&lt;span style="background: SpringGreen;"&gt;private&lt;/span&gt;&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;&lt;span style="background: SpringGreen;"&gt;static&lt;/span&gt;&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;&lt;span style="background: SpringGreen;"&gt;readonly&lt;/span&gt;&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;&lt;span style="background: SpringGreen;"&gt;object&lt;/span&gt;&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;LocalDataHashtableKey&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;=&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;&lt;span style="background: SpringGreen;"&gt;new&lt;/span&gt;&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;&lt;span style="background: SpringGreen;"&gt;object&lt;/span&gt;&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;(&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;);&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;&amp;nbsp;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;&lt;span style="color:#0000ff;"&gt;&lt;span style="background: SpringGreen;"&gt;private&lt;/span&gt;&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;&lt;span style="background: SpringGreen;"&gt;static&lt;/span&gt;&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;Hashtable&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;LocalHashtable&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;&lt;span style="background: SpringGreen;"&gt;{&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;    &lt;span style="background: SpringGreen;"&gt;get&lt;/span&gt; &lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;    &lt;span style="background: SpringGreen;"&gt;{&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;        &lt;span style="color:#0000ff;"&gt;&lt;span style="background: SpringGreen;"&gt;if&lt;/span&gt;&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;(&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;!RunningInWeb)&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;        &lt;span style="background: SpringGreen;"&gt;{&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;            &lt;span style="color:#0000ff;"&gt;&lt;span style="background: SpringGreen;"&gt;if&lt;/span&gt;&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;(&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;_localData&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;=&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;=&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;&lt;span style="background: SpringGreen;"&gt;null&lt;/span&gt;&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;)&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;                &lt;span style="background: SpringGreen;"&gt;_&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;localData&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;=&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;&lt;span style="background: SpringGreen;"&gt;new&lt;/span&gt;&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;Hashtable()&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;;&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;            &lt;span style="color:#0000ff;"&gt;&lt;span style="background: SpringGreen;"&gt;return&lt;/span&gt;&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;_&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;localData;&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;        &lt;span style="background: SpringGreen;"&gt;}&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;        &lt;span style="color:#0000ff;"&gt;&lt;span style="background: SpringGreen;"&gt;else&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;        &lt;span style="background: SpringGreen;"&gt;{&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;            &lt;span style="background: SpringGreen;"&gt;var&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;web_hashtable&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;=&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;HttpContext.Current.Items[LocalDataHashtableKey&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;]&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;&lt;span style="background: SpringGreen;"&gt;as&lt;/span&gt;&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;Hashtable&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;;&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;            &lt;span style="color:#0000ff;"&gt;&lt;span style="background: SpringGreen;"&gt;if&lt;/span&gt;&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;(&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;web_hashtable&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;=&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;=&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;&lt;span style="background: SpringGreen;"&gt;null&lt;/span&gt;&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;)&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;            &lt;span style="background: SpringGreen;"&gt;{&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;                &lt;span style="background: SpringGreen;"&gt;web_hashtable&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;=&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;&lt;span style="background: SpringGreen;"&gt;new&lt;/span&gt;&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;Hashtable()&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;;&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;                &lt;span style="background: SpringGreen;"&gt;HttpContext.Current.Items[LocalDataHashtableKey&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;]&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;=&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;web_hashtable&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;;&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;            &lt;span style="background: SpringGreen;"&gt;}&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;            &lt;span style="color:#0000ff;"&gt;&lt;span style="background: SpringGreen;"&gt;return&lt;/span&gt;&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;web_hashtable&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;;&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;        &lt;span style="background: SpringGreen;"&gt;}&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;    &lt;span style="background: SpringGreen;"&gt;}&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;&lt;span style="background: SpringGreen;"&gt;}&lt;/span&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;&lt;span style="background: SpringGreen;"&gt;In&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;this&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;code&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;I&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;use&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;the&lt;/span&gt; &lt;b&gt;&lt;span style="background: SpringGreen;"&gt;RunningInWeb&lt;/span&gt;&lt;/b&gt; &lt;span style="background: SpringGreen;"&gt;helper&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;method&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;to&lt;/span&gt; 
&lt;span style="background: SpringGreen;"&gt;distinguish&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;the&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;two&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;cases&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;.&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;In&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;the&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;case&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;of&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;NOT&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;running&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;in&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;web&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;context&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;I&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;test&lt;/span&gt; 
&lt;span style="background: SpringGreen;"&gt;whether&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;my&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;thread&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;static&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;_&lt;/span&gt;&lt;b&gt;&lt;span style="background: SpringGreen;"&gt;localData&lt;/span&gt;&lt;/b&gt; &lt;span style="background: SpringGreen;"&gt;field&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;is&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;equal&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;to&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;null&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;,&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;and&lt;/span&gt; 
&lt;span style="background: SpringGreen;"&gt;If&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;so&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;I&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;initialize&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;it&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;with&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;a&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;new&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;instance&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;of&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;type&lt;/span&gt; &lt;b&gt;&lt;span style="background: SpringGreen;"&gt;Hashtable&lt;/span&gt;&lt;/b&gt;&lt;span style="background: SpringGreen;"&gt;.&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;I&lt;/span&gt; 
&lt;span style="background: SpringGreen;"&gt;then&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;return&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;this&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;instance&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;.&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;On&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;the&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;other&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;hand&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;,&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;when&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;running&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;in&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;web&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;context&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;I&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;try&lt;/span&gt; 
&lt;span style="background: SpringGreen;"&gt;to&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;access&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;a&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;hash&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;table&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;instance&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;in&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;the&lt;/span&gt; &lt;b&gt;&lt;span style="background: SpringGreen;"&gt;Items&lt;/span&gt;&lt;/b&gt; &lt;span style="background: SpringGreen;"&gt;collection&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;of&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;the&lt;/span&gt; 
&lt;span style="background: SpringGreen;"&gt;current&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;Http&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;context&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;.&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;If&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;I&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;do&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;not&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;find&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;such&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;an&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;instance&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;then&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;I&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;create&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;a&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;new&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;one&lt;/span&gt; 
&lt;span style="background: SpringGreen;"&gt;and&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;put&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;it&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;into&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;the&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;items&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;collection&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;of&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;the&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;current&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;context&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;.&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;I&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;then&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;return&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;the&lt;/span&gt; 
&lt;span style="background: SpringGreen;"&gt;instance&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="background: SpringGreen;"&gt;Now&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;I&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;have&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;to&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;locate&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;every&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;place&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;in&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;the&lt;/span&gt; &lt;b&gt;&lt;span style="background: SpringGreen;"&gt;LocalData&lt;/span&gt;&lt;/b&gt; &lt;span style="background: SpringGreen;"&gt;class&lt;/span&gt; 
&lt;span style="background: SpringGreen;"&gt;where&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;I&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;access&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;the&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;_&lt;/span&gt;&lt;b&gt;&lt;span style="background: SpringGreen;"&gt;localData&lt;/span&gt;&lt;/b&gt; &lt;span style="background: SpringGreen;"&gt;field&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;directly&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;and&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;replace&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;it&lt;/span&gt; 
&lt;span style="background: SpringGreen;"&gt;with&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;a&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;reference&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;to&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;the&lt;/span&gt; &lt;b&gt;&lt;span style="background: SpringGreen;"&gt;LocalHashtable&lt;/span&gt;&lt;/b&gt; &lt;span style="background: SpringGreen;"&gt;property&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;.&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;E.g&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;.&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;the&lt;/span&gt; 
&lt;span style="background: SpringGreen;"&gt;indexer&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;will&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;have&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;to&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;be&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;changed&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;as&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;follows&lt;/span&gt;&lt;/p&gt;
&lt;div&gt;
&lt;div style="border-style:none;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;&lt;span style="color:#0000ff;"&gt;&lt;span style="background: SpringGreen;"&gt;public&lt;/span&gt;&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;&lt;span style="background: SpringGreen;"&gt;object&lt;/span&gt;&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;&lt;span style="background: SpringGreen;"&gt;this&lt;/span&gt;&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;[&lt;/span&gt;&lt;span style="color:#0000ff;"&gt;&lt;span style="background: SpringGreen;"&gt;object&lt;/span&gt;&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;key&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;]&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;&lt;span style="background: SpringGreen;"&gt;{&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;    &lt;span style="background: SpringGreen;"&gt;get&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;{&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;&lt;span style="background: SpringGreen;"&gt;return&lt;/span&gt;&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;LocalHashtable[key]&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;;&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;}&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;    &lt;span style="background: SpringGreen;"&gt;set&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;{&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;LocalHashtable[key&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;]&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;=&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;&lt;span style="background: SpringGreen;"&gt;value&lt;/span&gt;&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;;&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;}&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;&lt;span style="background: SpringGreen;"&gt;}&lt;/span&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;&lt;span style="background: SpringGreen;"&gt;Our&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;thread&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;-&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;and/or&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;Http&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;context&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;local&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;data&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;store&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;is&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;now&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;complete&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;and&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;we&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;can&lt;/span&gt; 
&lt;span style="background: SpringGreen;"&gt;use&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;it&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;in&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;our&lt;/span&gt; &lt;b&gt;&lt;span style="background: SpringGreen;"&gt;UnitOfWork&lt;/span&gt;&lt;/b&gt; &lt;span style="background: SpringGreen;"&gt;class&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;.&lt;/span&gt;&lt;/p&gt;
&lt;h2&gt;&lt;span style="background: SpringGreen;"&gt;Make&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;Unit&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;Of&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;Work&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;implementation&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;thread&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;safe&lt;/span&gt;&lt;/h2&gt;
&lt;p&gt;&lt;span style="background: SpringGreen;"&gt;To&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;make&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;our&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;unit&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;of&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;work&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;implementation&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;thread&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;safe&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;we&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;change&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;the&lt;/span&gt; 
&lt;span style="background: SpringGreen;"&gt;implementation&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;of&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;our&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;static&lt;/span&gt; &lt;b&gt;&lt;span style="background: SpringGreen;"&gt;UnitOfWork&lt;/span&gt;&lt;/b&gt; &lt;span style="background: SpringGreen;"&gt;class&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;as&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;shown&lt;/span&gt; 
&lt;span style="background: SpringGreen;"&gt;below&lt;/span&gt;&lt;/p&gt;
&lt;div&gt;
&lt;div style="border-style:none;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;&lt;span style="color:#0000ff;"&gt;&lt;span style="background: SpringGreen;"&gt;public&lt;/span&gt;&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;&lt;span style="background: SpringGreen;"&gt;static&lt;/span&gt;&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;&lt;span style="background: SpringGreen;"&gt;class&lt;/span&gt;&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;UnitOfWork&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;&lt;span style="background: SpringGreen;"&gt;{&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;    &lt;span style="color:#0000ff;"&gt;&lt;span style="background: SpringGreen;"&gt;private&lt;/span&gt;&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;&lt;span style="background: SpringGreen;"&gt;static&lt;/span&gt;&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;&lt;span style="background: SpringGreen;"&gt;readonly&lt;/span&gt;&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;IUnitOfWorkFactory&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;_&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;unitOfWorkFactory&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;=&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;&lt;span style="background: SpringGreen;"&gt;new&lt;/span&gt;&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;UnitOfWorkFactory()&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;;&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;&amp;nbsp;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;    &lt;span style="color:#0000ff;"&gt;&lt;span style="background: SpringGreen;"&gt;public&lt;/span&gt;&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;&lt;span style="background: SpringGreen;"&gt;static&lt;/span&gt;&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;Configuration&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;Configuration&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;    &lt;span style="background: SpringGreen;"&gt;{&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;        &lt;span style="background: SpringGreen;"&gt;get&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;{&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;&lt;span style="background: SpringGreen;"&gt;return&lt;/span&gt;&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;_&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;unitOfWorkFactory.Configuration;&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;}&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;    &lt;span style="background: SpringGreen;"&gt;}&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;&amp;nbsp;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;    &lt;span style="color:#0000ff;"&gt;&lt;span style="background: SpringGreen;"&gt;public&lt;/span&gt;&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;&lt;span style="background: SpringGreen;"&gt;const&lt;/span&gt;&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;&lt;span style="background: SpringGreen;"&gt;string&lt;/span&gt;&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;CurrentUnitOfWorkKey&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;=&lt;/span&gt; &lt;span style="color:#006080;"&gt;&lt;span style="background: SpringGreen;"&gt;&amp;quot;CurrentUnitOfWork.Key&amp;quot;&lt;/span&gt;&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;;&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;&amp;nbsp;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;    &lt;span style="color:#0000ff;"&gt;&lt;span style="background: SpringGreen;"&gt;private&lt;/span&gt;&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;&lt;span style="background: SpringGreen;"&gt;static&lt;/span&gt;&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;IUnitOfWork&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;CurrentUnitOfWork&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;    &lt;span style="background: SpringGreen;"&gt;{&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;        &lt;span style="background: SpringGreen;"&gt;get&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;{&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;&lt;span style="background: SpringGreen;"&gt;return&lt;/span&gt;&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;Local.Data[CurrentUnitOfWorkKey&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;]&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;&lt;span style="background: SpringGreen;"&gt;as&lt;/span&gt;&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;IUnitOfWork&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;;&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;}&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;        &lt;span style="background: SpringGreen;"&gt;set&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;{&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;Local.Data[CurrentUnitOfWorkKey&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;]&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;=&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;&lt;span style="background: SpringGreen;"&gt;value&lt;/span&gt;&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;;&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;}&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;    &lt;span style="background: SpringGreen;"&gt;}&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;&amp;nbsp;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;    &lt;span style="color:#0000ff;"&gt;&lt;span style="background: SpringGreen;"&gt;public&lt;/span&gt;&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;&lt;span style="background: SpringGreen;"&gt;static&lt;/span&gt;&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;IUnitOfWork&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;Current&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;    &lt;span style="background: SpringGreen;"&gt;{&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;        &lt;span style="background: SpringGreen;"&gt;get&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;        &lt;span style="background: SpringGreen;"&gt;{&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;            &lt;span style="background: SpringGreen;"&gt;var&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;unitOfWork&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;=&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;CurrentUnitOfWork&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;;&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;            &lt;span style="color:#0000ff;"&gt;&lt;span style="background: SpringGreen;"&gt;if&lt;/span&gt;&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;(&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;unitOfWork&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;=&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;=&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;&lt;span style="background: SpringGreen;"&gt;null&lt;/span&gt;&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;)&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;                &lt;span style="color:#0000ff;"&gt;&lt;span style="background: SpringGreen;"&gt;throw&lt;/span&gt;&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;&lt;span style="background: SpringGreen;"&gt;new&lt;/span&gt;&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;InvalidOperationException&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;(&lt;/span&gt;&lt;span style="color:#006080;"&gt;&lt;span style="background: SpringGreen;"&gt;&amp;quot;You&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;are&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;not&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;in&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;a&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;unit&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;of&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;work&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;)&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;;&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;            &lt;span style="color:#0000ff;"&gt;&lt;span style="background: SpringGreen;"&gt;return&lt;/span&gt;&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;unitOfWork&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;;&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;        &lt;span style="background: SpringGreen;"&gt;}&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;    &lt;span style="background: SpringGreen;"&gt;}&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;&amp;nbsp;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;    &lt;span style="color:#0000ff;"&gt;&lt;span style="background: SpringGreen;"&gt;public&lt;/span&gt;&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;&lt;span style="background: SpringGreen;"&gt;static&lt;/span&gt;&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;&lt;span style="background: SpringGreen;"&gt;bool&lt;/span&gt;&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;IsStarted&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;    &lt;span style="background: SpringGreen;"&gt;{&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;        &lt;span style="background: SpringGreen;"&gt;get&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;{&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;&lt;span style="background: SpringGreen;"&gt;return&lt;/span&gt;&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;CurrentUnitOfWork&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;!&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;=&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;&lt;span style="background: SpringGreen;"&gt;null&lt;/span&gt;&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;;&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;}&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;    &lt;span style="background: SpringGreen;"&gt;}&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;&amp;nbsp;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;    &lt;span style="color:#0000ff;"&gt;&lt;span style="background: SpringGreen;"&gt;public&lt;/span&gt;&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;&lt;span style="background: SpringGreen;"&gt;static&lt;/span&gt;&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;ISession&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;CurrentSession&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;    &lt;span style="background: SpringGreen;"&gt;{&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;        &lt;span style="background: SpringGreen;"&gt;get&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;{&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;&lt;span style="background: SpringGreen;"&gt;return&lt;/span&gt;&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;_&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;unitOfWorkFactory.CurrentSession;&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;}&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;        &lt;span style="color:#0000ff;"&gt;&lt;span style="background: SpringGreen;"&gt;internal&lt;/span&gt;&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;set&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;{&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;_&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;unitOfWorkFactory.CurrentSession&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;=&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;&lt;span style="background: SpringGreen;"&gt;value&lt;/span&gt;&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;;&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;}&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;    &lt;span style="background: SpringGreen;"&gt;}&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;&amp;nbsp;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;    &lt;span style="color:#0000ff;"&gt;&lt;span style="background: SpringGreen;"&gt;public&lt;/span&gt;&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;&lt;span style="background: SpringGreen;"&gt;static&lt;/span&gt;&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;IUnitOfWork&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;Start(&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;)&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;    &lt;span style="background: SpringGreen;"&gt;{&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;        &lt;span style="color:#0000ff;"&gt;&lt;span style="background: SpringGreen;"&gt;if&lt;/span&gt;&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;(&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;CurrentUnitOfWork&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;!&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;=&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;&lt;span style="background: SpringGreen;"&gt;null&lt;/span&gt;&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;)&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;            &lt;span style="color:#0000ff;"&gt;&lt;span style="background: SpringGreen;"&gt;throw&lt;/span&gt;&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;&lt;span style="background: SpringGreen;"&gt;new&lt;/span&gt;&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;InvalidOperationException&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;(&lt;/span&gt;&lt;span style="color:#006080;"&gt;&lt;span style="background: SpringGreen;"&gt;&amp;quot;You&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;cannot&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;start&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;more&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;than&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;one&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;unit&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;of&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;work&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;at&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;the&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;same&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;time&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;.&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;)&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;;&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;        &lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;        &lt;span style="background: SpringGreen;"&gt;var&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;unitOfWork&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;=&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;_&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;unitOfWorkFactory.Create();&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;        &lt;span style="background: SpringGreen;"&gt;CurrentUnitOfWork&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;=&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;unitOfWork&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;;&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;        &lt;span style="color:#0000ff;"&gt;&lt;span style="background: SpringGreen;"&gt;return&lt;/span&gt;&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;unitOfWork&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;;&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;    &lt;span style="background: SpringGreen;"&gt;}&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;&amp;nbsp;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;    &lt;span style="color:#0000ff;"&gt;&lt;span style="background: SpringGreen;"&gt;public&lt;/span&gt;&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;&lt;span style="background: SpringGreen;"&gt;static&lt;/span&gt;&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;&lt;span style="background: SpringGreen;"&gt;void&lt;/span&gt;&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;DisposeUnitOfWork(IUnitOfWorkImplementor&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;unitOfWork&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;)&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;    &lt;span style="background: SpringGreen;"&gt;{&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;        &lt;span style="background: SpringGreen;"&gt;CurrentUnitOfWork&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;=&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;&lt;span style="background: SpringGreen;"&gt;null&lt;/span&gt;&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;;&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;    &lt;span style="background: SpringGreen;"&gt;}&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;&lt;span style="background: SpringGreen;"&gt;}&lt;/span&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;&lt;span style="background: SpringGreen;"&gt;As&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;you&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;can&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;see&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;the&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;field&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;_&lt;/span&gt;&lt;b&gt;&lt;span style="background: SpringGreen;"&gt;innerUnitOfWork&lt;/span&gt;&lt;/b&gt; &lt;span style="background: SpringGreen;"&gt;has&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;gone&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;and&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;is&lt;/span&gt; 
&lt;span style="background: SpringGreen;"&gt;replaced&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;by&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;a&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;private&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;property&lt;/span&gt; &lt;b&gt;&lt;span style="background: SpringGreen;"&gt;CurrentUnitOfWork&lt;/span&gt;&lt;/b&gt;&lt;span style="background: SpringGreen;"&gt;.&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;This&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;property&lt;/span&gt; 
&lt;span style="background: SpringGreen;"&gt;in&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;turn&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;uses&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;the&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;previously&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;defined&lt;/span&gt; &lt;b&gt;&lt;span style="background: SpringGreen;"&gt;Local&lt;/span&gt; &lt;/b&gt;&lt;span style="background: SpringGreen;"&gt;class&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;to&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;store&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;the&lt;/span&gt; 
&lt;span style="background: SpringGreen;"&gt;current&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;unit&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;of&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;work&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;item&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;.&lt;/span&gt; &lt;/p&gt;
&lt;p&gt;&lt;span style="background: SpringGreen;"&gt;Note&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;that&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;there&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;is&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;one&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;place&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;in&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;our&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;unit&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;tests&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;that&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;makes&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;a&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;reference&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;to&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;the&lt;/span&gt; 
&lt;span style="background: SpringGreen;"&gt;field&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;_&lt;/span&gt;&lt;b&gt;&lt;span style="background: SpringGreen;"&gt;innerUnitOfWork&lt;/span&gt;&lt;/b&gt; &lt;span style="background: SpringGreen;"&gt;and&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;must&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;thus&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;be&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;changed&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;.&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;It&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;&amp;#39;&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;s&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;the&lt;/span&gt; 
&lt;span style="background: SpringGreen;"&gt;method&lt;/span&gt; &lt;b&gt;&lt;span style="background: SpringGreen;"&gt;ResetUnitOfWork&lt;/span&gt;&lt;/b&gt; &lt;span style="background: SpringGreen;"&gt;in&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;the&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;class&lt;/span&gt; 
&lt;b&gt;&lt;span style="background: SpringGreen;"&gt;UnitOfWork_With_Factory_Fixture&lt;/span&gt;&lt;/b&gt;&lt;span style="background: SpringGreen;"&gt;.&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;The&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;new&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;implementation&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;is&lt;/span&gt;&lt;/p&gt;
&lt;div&gt;
&lt;div style="border-style:none;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;&lt;span style="color:#0000ff;"&gt;&lt;span style="background: SpringGreen;"&gt;private&lt;/span&gt;&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;&lt;span style="background: SpringGreen;"&gt;void&lt;/span&gt;&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;ResetUnitOfWork(&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;)&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;&lt;span style="background: SpringGreen;"&gt;{&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;    &lt;span style="color:#008000;"&gt;&lt;span style="background: SpringGreen;"&gt;/&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;/&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;assert&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;that&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;the&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;UnitOfWork&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;is&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;reset&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;    &lt;span style="background: SpringGreen;"&gt;var&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;propertyInfo&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;=&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;&lt;span style="background: SpringGreen;"&gt;typeof&lt;/span&gt;&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;(&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;UnitOfWork).GetProperty(&lt;/span&gt;&lt;span style="color:#006080;"&gt;&lt;span style="background: SpringGreen;"&gt;&amp;quot;CurrentUnitOfWork&amp;quot;&lt;/span&gt;&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;,&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;                        &lt;span style="background: SpringGreen;"&gt;BindingFlags.Static&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;|&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;BindingFlags.SetProperty&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;|&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;BindingFlags.NonPublic)&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;;&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;    &lt;span style="background: SpringGreen;"&gt;propertyInfo.SetValue&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;(&lt;/span&gt;&lt;span style="color:#0000ff;"&gt;&lt;span style="background: SpringGreen;"&gt;null&lt;/span&gt;&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;,&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;&lt;span style="background: SpringGreen;"&gt;null&lt;/span&gt;&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;,&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;&lt;span style="background: SpringGreen;"&gt;null&lt;/span&gt;&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;)&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;;&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;&lt;span style="background: SpringGreen;"&gt;}&lt;/span&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;&lt;span style="background: SpringGreen;"&gt;When&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;run&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;,&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;all&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;tests&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;should&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;again&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;pass&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;.&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;So&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;now&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;our&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;implementation&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;of&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;the&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;unit&lt;/span&gt; 
&lt;span style="background: SpringGreen;"&gt;of&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;work&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;is&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;thread&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;safe&lt;/span&gt;&lt;span style="background: SpringGreen;"&gt;.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="background: SpringGreen;"&gt;You&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;can&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;find&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;the&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;full&lt;/span&gt; &lt;span style="background: SpringGreen;"&gt;code&lt;/span&gt; &lt;a href="http://hibernatingrhinos.googlecode.com/svn/trunk/UnitOfWork/"&gt;&lt;span style="background: SpringGreen;"&gt;here&lt;/span&gt;&lt;/a&gt;&lt;span style="background: SpringGreen;"&gt;.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;</description></item><item><title>NHibernate and the Unit of Work Pattern</title><link>http://nhforge.org/wikis/patternsandpractices/nhibernate-and-the-unit-of-work-pattern/revision/1.aspx</link><pubDate>Tue, 23 Sep 2008 19:39:53 GMT</pubDate><guid isPermaLink="false">45f813f2-f1c4-4eda-a619-288e3cadc793:152</guid><dc:creator>gabriel.schenker</dc:creator><comments>http://nhforge.org/wikis/patternsandpractices/nhibernate-and-the-unit-of-work-pattern/comments.aspx</comments><description>Revision 1 posted to Patterns &amp;amp; Practices by gabriel.schenker on 23/09/2008 04:39:53 p.m.&lt;br /&gt;
&lt;h2&gt;Introduction&lt;/h2&gt;
&lt;p&gt;Martin Fowler &lt;a href="http://martinfowler.com/eaaCatalog/unitOfWork.html"&gt;writes&lt;/a&gt;: &lt;/p&gt;
&lt;p&gt;&amp;quot;When you&amp;#39;re pulling data in and out of a database, it&amp;#39;s important to keep 
track of what you&amp;#39;ve changed; otherwise, that data won&amp;#39;t be written back into 
the database. Similarly you have to insert new objects you create and remove any 
objects you delete.&amp;quot;&lt;/p&gt;
&lt;p&gt;and&lt;/p&gt;
&lt;p&gt;&amp;quot;A &lt;strong&gt;Unit of Work&lt;/strong&gt; keeps track of everything you do during a 
&lt;em&gt;business transaction&lt;/em&gt; that can affect the database. When you&amp;#39;re done, it 
figures out everything that needs to be done to alter the database as a result 
of your work.&amp;quot;&lt;/p&gt;
&lt;p&gt;In NHibernate we have the &lt;strong&gt;Session&lt;/strong&gt; object which is a Unit of 
Work (UoW) container. The session object keeps track of all objects you load, 
new objects you add, existing objects you delete and changes you make to any of 
these objects. Only when &lt;strong&gt;flushing&lt;/strong&gt; the session will the database 
be altered (that is: will the necessary create, update and delete statements be 
sent to the database).&lt;/p&gt;
&lt;p&gt;Now, working directly with the NHibernate session object makes absolute 
sense. But some times you rather want to abstract the data manipulation 
interface from a specific infrastructure implementation &amp;agrave; la NHibernate.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Note&lt;/strong&gt;: most of the design ideas and implementation details 
presented here originate from &lt;a href="http://www.ayende.com/"&gt;Ayende&lt;/a&gt;&amp;#39;s 
UnitOfWork implemented in the &lt;strong&gt;Rhino.Commons&lt;/strong&gt; which you can get 
&lt;a href="http://rhino-tools.svn.sourceforge.net/svnroot/rhino-tools/trunk"&gt;here&lt;/a&gt;.&lt;/p&gt;
&lt;h2&gt;Design and Implementation (TDD)&lt;/h2&gt;
&lt;h3&gt;Some thought about TDD&lt;/h3&gt;
&lt;p&gt;I want to implement a UnitOfWork pattern for NHibernate and I want to do it 
by using &lt;a href="http://en.wikipedia.org/wiki/Test-driven_development"&gt;TDD&lt;/a&gt;. 
For a beginner (like I was myself not so long ago) it seems unnatural at the 
beginning. We introduce a huge overhead you might think. You might also think 
that we have to write at least double the code as when doing the development 
without TDD. But wait until you have to start to debug your application... or 
until the customer wants to have something changed in the application... or 
until you have to re-factor you application... Then you will immediately see and 
feel the benefits of a good test coverage.&lt;/p&gt;
&lt;h3&gt;Attention: Multi-Threading ahead&lt;/h3&gt;
&lt;p&gt;Please not that the implementation presented here is strictly 
&lt;strong&gt;NOT&lt;/strong&gt; thread safe!!! I want to reduce the complexity of this 
first implementation. But &lt;strong&gt;I promise&lt;/strong&gt; that in a following post 
I&amp;#39;ll show you how to make the implementation of the unit of work pattern thread 
safe and thus useful for e.g. Web scenarios.&lt;/p&gt;
&lt;h3&gt;The UnitOfWork Class&lt;/h3&gt;
&lt;p&gt;To start with: I want to have an easy way to &lt;strong&gt;start&lt;/strong&gt; a new 
UoW, in any place of my application have access to the &lt;strong&gt;current&lt;/strong&gt; 
UoW and &lt;strong&gt;commit&lt;/strong&gt; the &lt;em&gt;business transaction&lt;/em&gt; represented by 
my UoW. We can do this with a static class called UnitOfWork&lt;/p&gt;
&lt;p&gt;&lt;a&gt;&lt;img style="border-width:0px;" alt="image" border="0" height="179" width="471" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;The method start creates and returns an instance of a 
&lt;strong&gt;UnitOfWorkImplementor&lt;/strong&gt; class which implements the interface 
&lt;strong&gt;IUnitOfWork&lt;/strong&gt;. As you can see then interface IUnitOfWork inherits 
from IDisposable. So we can define that the &lt;em&gt;business transaction&lt;/em&gt; is 
ended when the UoW is disposed. Now, if we do nothing else then nothing should 
happen, that is no changes should be propagated to the database. To commit a 
&lt;em&gt;business transaction&lt;/em&gt; we have to explicitly call a method of the UoW. 
Let&amp;#39;s call this method &lt;strong&gt;TransactionalFlush&lt;/strong&gt;. In doing so all 
changes recorded by the UoW are committed to the database in one go.&lt;/p&gt;
&lt;p&gt;Now let&amp;#39;s start to implement this! We are doing TDD, aren&amp;#39;t we? So we will 
write our first test (if you are not sure how to best setup a new solution for 
TDD please consult &lt;a href="http://blogs.hibernatingrhinos.com/nhibernate/archive/2008/04/06/how-to-setup-a-new-solution.aspx"&gt;this&lt;/a&gt; 
post). I define a new solution with two projects as follows&lt;/p&gt;
&lt;p&gt;&lt;a&gt;&lt;img style="border-width:0px;" alt="image" border="0" height="135" width="304" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Add a class UnitOfWork_Fixture.cs to the test project and implement the first 
test like this&lt;/p&gt;
&lt;div&gt;
&lt;div style="border-style:none;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;[TestFixture]&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;&lt;span style="color:#0000ff;"&gt;public&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;class&lt;/span&gt; UnitOfWork_Fixture&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;{&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;    &lt;span style="color:#0000ff;"&gt;private&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;readonly&lt;/span&gt; MockRepository _mocks = &lt;span style="color:#0000ff;"&gt;new&lt;/span&gt; MockRepository();&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;&amp;nbsp;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;    [Test]&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;    &lt;span style="color:#0000ff;"&gt;public&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;void&lt;/span&gt; Can_Start_UnitOfWork()&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;    {&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;        IUnitOfWork uow = UnitOfWork.Start();&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;    }&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;}&lt;/pre&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;Of course this test will not compile since you don&amp;#39;t have the types 
UnitOfWork and IUnitOfWork defined yet. Let &lt;a href="http://www.jetbrains.com/resharper/"&gt;Resharper&lt;/a&gt; create them for you (or 
implement them by hand)&lt;/p&gt;
&lt;div&gt;
&lt;div style="border-style:none;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;&lt;span style="color:#0000ff;"&gt;public&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;static&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;class&lt;/span&gt; UnitOfWork&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;{&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;    &lt;span style="color:#0000ff;"&gt;public&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;static&lt;/span&gt; IUnitOfWork Start()&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;    {&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;        &lt;span style="color:#0000ff;"&gt;throw&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;new&lt;/span&gt; NotImplementedException();&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;    }&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;&amp;nbsp;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;    &lt;span style="color:#0000ff;"&gt;public&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;static&lt;/span&gt; IUnitOfWork Current { get; &lt;span style="color:#0000ff;"&gt;private&lt;/span&gt; set; }&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;}&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;&amp;nbsp;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;&lt;span style="color:#0000ff;"&gt;public&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;interface&lt;/span&gt; IUnitOfWork : IDisposable&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;{&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;}&lt;/pre&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;Now the test will compile but it will fail! Of course, you haven&amp;#39;t 
implemented the Start method so far. In this method we must now create a new UoW 
and return it to the caller. A UoW is a complex beast and should therefore be 
constructed in a factory. So let&amp;#39;s define a factory Interface IUnitOfWorkFactory 
with a method Create which returns a UoW implementing the interface 
IUnitOfWork.&lt;/p&gt;
&lt;div&gt;
&lt;div style="border-style:none;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;&lt;span style="color:#0000ff;"&gt;public&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;interface&lt;/span&gt; IUnitOfWorkFactory&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;{&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;  IUnitOfWork Create();&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;}&lt;/pre&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;since we want to test our UnitOfWork class in isolation we have to mock all 
other dependencies line the unit of work factory. I&amp;#39;ll use 
&lt;strong&gt;Rhino.Mocks&lt;/strong&gt; as my mocking framework (Please refer to 
documentation &lt;a href="http://www.ayende.com/wiki/Rhino+Mocks+Documentation.ashx"&gt;here&lt;/a&gt;). I 
want to test that when calling the start method of the UnitOfWork class the 
factory gets called. So I extend my test function&lt;/p&gt;
&lt;div&gt;
&lt;div style="border-style:none;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;[Test]&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;&lt;span style="color:#0000ff;"&gt;public&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;void&lt;/span&gt; Can_Start_UnitOfWork()&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;{&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;    var factory = _mocks.DynamicMock&amp;lt;IUnitOfWorkFactory&amp;gt;();&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;    var unitOfWork = _mocks.DynamicMock&amp;lt;IUnitOfWork&amp;gt;();&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;&amp;nbsp;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;    &lt;span style="color:#008000;"&gt;// brute force attack to set my own factory via reflection&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;    var fieldInfo = &lt;span style="color:#0000ff;"&gt;typeof&lt;/span&gt;(UnitOfWork).GetField(&lt;span style="color:#006080;"&gt;&amp;quot;_unitOfWorkFactory&amp;quot;&lt;/span&gt;, &lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;        BindingFlags.Static | BindingFlags.SetField | BindingFlags.NonPublic);&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;    fieldInfo.SetValue(&lt;span style="color:#0000ff;"&gt;null&lt;/span&gt;, factory);&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;&amp;nbsp;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;    &lt;span style="color:#0000ff;"&gt;using&lt;/span&gt;(_mocks.Record())&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;    {&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;        Expect.Call(factory.Create()).Return(unitOfWork);&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;    }&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;    &lt;span style="color:#0000ff;"&gt;using&lt;/span&gt;(_mocks.Playback())&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;    {&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;        var uow = UnitOfWork.Start();&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;    }&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;}&lt;/pre&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;In the first two lines of code I mock the external dependencies of the 
UnitOfWork class. Then I do something you should not do very often (but I have 
good reasons doing so here and I promise it&amp;#39;s the only time I&amp;#39;ll do it in this 
project...). I set a private field of the UnitOfWork class with a value by using 
reflection. I could implement a public setter in the class but as I would only 
need it for this test and I want to keep the class interface as simple as 
possible I chose to do it via reflection.&lt;/p&gt;
&lt;p&gt;In the&amp;nbsp; record phase I define my expectation (namely that the factory create 
method is called) and in the playback phase I invoke the Start method which I 
want to test. The test will compile but fail to execute. I have not yet defined 
the private static field _unitOfWorkFactory and I also do not call the factory. 
So let&amp;#39;s modify our code...&lt;/p&gt;
&lt;div&gt;
&lt;div style="border-style:none;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;&lt;span style="color:#0000ff;"&gt;public&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;static&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;class&lt;/span&gt; UnitOfWork&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;{&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;    &lt;span style="color:#0000ff;"&gt;private&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;static&lt;/span&gt; IUnitOfWorkFactory _unitOfWorkFactory;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;    &lt;span style="color:#0000ff;"&gt;private&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;static&lt;/span&gt; IUnitOfWork _innerUnitOfWork;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;&amp;nbsp;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;    &lt;span style="color:#0000ff;"&gt;public&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;static&lt;/span&gt; IUnitOfWork Start()&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;    {&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;        _innerUnitOfWork = _unitOfWorkFactory.Create();&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;        &lt;span style="color:#0000ff;"&gt;return&lt;/span&gt; _innerUnitOfWork;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;    }&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;&amp;nbsp;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;    &lt;span style="color:#0000ff;"&gt;public&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;static&lt;/span&gt; IUnitOfWork Current { get; &lt;span style="color:#0000ff;"&gt;private&lt;/span&gt; set; }&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;}&lt;/pre&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;now the test will pass.&lt;/p&gt;
&lt;p&gt;Since in all our test regarding the UnitOfWork class we will always need it 
with an injected factory we define a new test fixture with a context setup for 
our specific needs. We put the respective code in the 
&lt;strong&gt;SetupContext&lt;/strong&gt; and &lt;strong&gt;TearDownContext&lt;/strong&gt; methods&lt;/p&gt;
&lt;div&gt;
&lt;div style="border-style:none;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;[TestFixture]&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;&lt;span style="color:#0000ff;"&gt;public&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;class&lt;/span&gt; UnitOfWork_With_Factory_Fixture&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;{&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;    &lt;span style="color:#0000ff;"&gt;private&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;readonly&lt;/span&gt; MockRepository _mocks = &lt;span style="color:#0000ff;"&gt;new&lt;/span&gt; MockRepository();&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;    &lt;span style="color:#0000ff;"&gt;private&lt;/span&gt; IUnitOfWorkFactory _factory;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;    &lt;span style="color:#0000ff;"&gt;private&lt;/span&gt; IUnitOfWork _unitOfWork;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;&amp;nbsp;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;    [SetUp]&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;    &lt;span style="color:#0000ff;"&gt;public&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;void&lt;/span&gt; SetupContext()&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;    {&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;        _factory = _mocks.DynamicMock&amp;lt;IUnitOfWorkFactory&amp;gt;();&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;        _unitOfWork = _mocks.DynamicMock&amp;lt;IUnitOfWork&amp;gt;();&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;&amp;nbsp;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;        &lt;span style="color:#008000;"&gt;// brute force attack to set my own factory via reflection&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;        var fieldInfo = &lt;span style="color:#0000ff;"&gt;typeof&lt;/span&gt;(UnitOfWork).GetField(&lt;span style="color:#006080;"&gt;&amp;quot;_unitOfWorkFactory&amp;quot;&lt;/span&gt;,&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;            BindingFlags.Static | BindingFlags.SetField | BindingFlags.NonPublic);&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;        fieldInfo.SetValue(&lt;span style="color:#0000ff;"&gt;null&lt;/span&gt;, _factory);&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;&amp;nbsp;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;        _mocks.BackToRecordAll();&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;        SetupResult.For(_factory.Create()).Return(_unitOfWork);&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;        _mocks.ReplayAll();&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;    }&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;&amp;nbsp;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;    [TearDown]&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;    &lt;span style="color:#0000ff;"&gt;public&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;void&lt;/span&gt; TearDownContext()&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;    {&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;        _mocks.VerifyAll();&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;    }&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;}&lt;/pre&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;&lt;strong&gt;Note&lt;/strong&gt;: in the second last line of the 
&lt;strong&gt;SetupContext&lt;/strong&gt; method we define that each time the method Create 
of the factory object is called (by the UnitOfWork Start method) we want it to 
return our predefined mocked _&lt;strong&gt;unitOfWork&lt;/strong&gt; instance.&lt;/p&gt;
&lt;p&gt;Trying to start a UoW if there is already one active should throw a 
meaningful exception. This is the test&lt;/p&gt;
&lt;div&gt;
&lt;div style="border-style:none;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;[Test]&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;&lt;span style="color:#0000ff;"&gt;public&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;void&lt;/span&gt; Starting_UnitOfWork_if_already_started_throws()&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;{&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;    UnitOfWork.Start();&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;    &lt;span style="color:#0000ff;"&gt;try&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;    {&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;        UnitOfWork.Start();&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;    }&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;    &lt;span style="color:#0000ff;"&gt;catch&lt;/span&gt; (InvalidOperationException ex)&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;    { }&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;}&lt;/pre&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;As a consequence we have to extend our Start method in the UnitOfWork 
class&lt;/p&gt;
&lt;div&gt;
&lt;div style="border-style:none;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;&lt;span style="color:#0000ff;"&gt;public&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;static&lt;/span&gt; IUnitOfWork Start()&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;{&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;    &lt;span style="color:#0000ff;"&gt;if&lt;/span&gt; (_innerUnitOfWork != &lt;span style="color:#0000ff;"&gt;null&lt;/span&gt;)&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;        &lt;span style="color:#0000ff;"&gt;throw&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;new&lt;/span&gt; InvalidOperationException(&lt;span style="color:#006080;"&gt;&amp;quot;You cannot start more than one unit of work at the same time.&amp;quot;&lt;/span&gt;);&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;    &lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;    _innerUnitOfWork = _unitOfWorkFactory.Create();&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;    &lt;span style="color:#0000ff;"&gt;return&lt;/span&gt; _innerUnitOfWork;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;}&lt;/pre&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;Now I have another problem: After the test is finished the static field 
_&lt;strong&gt;innerUnitOfWork&lt;/strong&gt; of my &lt;strong&gt;UnitOfWork&lt;/strong&gt; class is set 
to a value other than &lt;strong&gt;null&lt;/strong&gt;. This will have a undesired side 
effect to the following test. I have to reset this field. Again in this special 
case I&amp;#39;ll do it via reflection to not clutter the interface of my class (static 
classes are difficult more complex to deal with in TDD than non static 
classes...). We do reset our UnitOfWork class in the TearDownContext method&lt;/p&gt;
&lt;div&gt;
&lt;div style="border-style:none;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;[TearDown]&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;&lt;span style="color:#0000ff;"&gt;public&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;void&lt;/span&gt; TearDownContext()&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;{&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;    _mocks.VerifyAll();&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;&amp;nbsp;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;    &lt;span style="color:#008000;"&gt;// assert that the UnitOfWork is reset&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;    var fieldInfo = &lt;span style="color:#0000ff;"&gt;typeof&lt;/span&gt;(UnitOfWork).GetField(&lt;span style="color:#006080;"&gt;&amp;quot;_innerUnitOfWork&amp;quot;&lt;/span&gt;,&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;        BindingFlags.Static | BindingFlags.SetField | BindingFlags.NonPublic);&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;    fieldInfo.SetValue(&lt;span style="color:#0000ff;"&gt;null&lt;/span&gt;, &lt;span style="color:#0000ff;"&gt;null&lt;/span&gt;);&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;}&lt;/pre&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;Next we want to be able to access the current unit of work. As usual we first 
implement a test&lt;/p&gt;
&lt;div&gt;
&lt;div style="border-style:none;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;[Test]&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;&lt;span style="color:#0000ff;"&gt;public&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;void&lt;/span&gt; Can_access_current_unit_of_work()&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;{&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;    IUnitOfWork uow = UnitOfWork.Start();&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;    var current = UnitOfWork.Current;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;    Assert.AreSame(uow, current);&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;}&lt;/pre&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;You can figure out what code you need to implement for the test to pass.&lt;/p&gt;
&lt;p&gt;We also want to assert that when accessing the current UoW if no UoW has been 
started that a meaningful exception is thrown&lt;/p&gt;
&lt;div&gt;
&lt;div style="border-style:none;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;[Test]&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;&lt;span style="color:#0000ff;"&gt;public&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;void&lt;/span&gt; Accessing_Current_UnitOfWork_if_not_started_throws()&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;{&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;    &lt;span style="color:#0000ff;"&gt;try&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;    {&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;        var current = UnitOfWork.Current;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;    }&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;    &lt;span style="color:#0000ff;"&gt;catch&lt;/span&gt; (InvalidOperationException ex)&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;    { }&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;}&lt;/pre&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;now my implementation of the Current property in the UnitOfWork class is as 
follows&lt;/p&gt;
&lt;div&gt;
&lt;div style="border-style:none;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;&lt;span style="color:#0000ff;"&gt;public&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;static&lt;/span&gt; IUnitOfWork Current&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;{&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;    get&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;    {&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;        &lt;span style="color:#0000ff;"&gt;if&lt;/span&gt; (_innerUnitOfWork == &lt;span style="color:#0000ff;"&gt;null&lt;/span&gt;)&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;            &lt;span style="color:#0000ff;"&gt;throw&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;new&lt;/span&gt; InvalidOperationException(&lt;span style="color:#006080;"&gt;&amp;quot;You are not in a unit of work.&amp;quot;&lt;/span&gt;);&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;        &lt;span style="color:#0000ff;"&gt;return&lt;/span&gt; _innerUnitOfWork;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;    }&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;}&lt;/pre&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;Next we want a property on the class which tells us whether a UoW is started 
or not. The test for it&lt;/p&gt;
&lt;div&gt;
&lt;div style="border-style:none;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;[Test]&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;&lt;span style="color:#0000ff;"&gt;public&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;void&lt;/span&gt; Can_test_if_UnitOfWork_Is_Started()&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;{&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;    Assert.IsFalse(UnitOfWork.IsStarted);&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;&amp;nbsp;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;    IUnitOfWork uow = UnitOfWork.Start();&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;    Assert.IsTrue(UnitOfWork.IsStarted);&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;}&lt;/pre&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;It&amp;#39;s getting boring isn&amp;#39;t it... But this is the way &lt;strong&gt;TDD&lt;/strong&gt; 
works. You always think (hard) on what you need and then you implement the test 
with which you can proof that you get it as you want it. Only then you implement 
the functionality needed to fulfill the test. If you do so you automatically 
follow the &lt;strong&gt;YAGNI&lt;/strong&gt; principle (you ain&amp;#39;t gona need it) that is you 
only implement the code you really need!&lt;/p&gt;
&lt;p&gt;We can fulfill the test like so&lt;/p&gt;
&lt;div&gt;
&lt;div style="border-style:none;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;&lt;span style="color:#0000ff;"&gt;public&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;static&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;bool&lt;/span&gt; IsStarted&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;{&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;    get { &lt;span style="color:#0000ff;"&gt;return&lt;/span&gt; _innerUnitOfWork != &lt;span style="color:#0000ff;"&gt;null&lt;/span&gt;; }&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;}&lt;/pre&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;The UnitOfWork class is now a perfect wrapper for the NHibernate session 
object. Though for some advance scenarios I would like to have access to the 
session object related to my UoW. As a consequence I&amp;#39;ll implement a read only 
property CurrentSession in the UnitOfWork class. Lets again start with the 
test&lt;/p&gt;
&lt;div&gt;
&lt;div style="border-style:none;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;[Test]&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;&lt;span style="color:#0000ff;"&gt;public&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;void&lt;/span&gt; Can_get_valid_current_session_if_UoW_is_started()&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;{&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;    &lt;span style="color:#0000ff;"&gt;using&lt;/span&gt; (UnitOfWork.Start())&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;    {&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;        ISession session = UnitOfWork.CurrentSession;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;        Assert.IsNotNull(session);&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;    }&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;}&lt;/pre&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;and the implementation&lt;/p&gt;
&lt;div&gt;
&lt;div style="border-style:none;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;&lt;span style="color:#0000ff;"&gt;public&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;static&lt;/span&gt; ISession CurrentSession&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;{&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;    get { &lt;span style="color:#0000ff;"&gt;return&lt;/span&gt; _unitOfWorkFactory.CurrentSession; }&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;    &lt;span style="color:#0000ff;"&gt;internal&lt;/span&gt; set { _unitOfWorkFactory.CurrentSession = &lt;span style="color:#0000ff;"&gt;value&lt;/span&gt;; }&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;}&lt;/pre&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;Note that I have just delegated the call to the factory class. Thus to make 
the test pass I have to add two additional lines to the SetupContext method of 
the test fixture where I mock a session object and setup the result for a call 
to the property CurrentSession of the factory.&lt;/p&gt;
&lt;div&gt;
&lt;div style="border-style:none;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;[SetUp]&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;&lt;span style="color:#0000ff;"&gt;public&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;void&lt;/span&gt; SetupContext()&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;{&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;    _factory = _mocks.DynamicMock&amp;lt;IUnitOfWorkFactory&amp;gt;();&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;    _unitOfWork = _mocks.DynamicMock&amp;lt;IUnitOfWork&amp;gt;();&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;    _session = _mocks.DynamicMock&amp;lt;ISession&amp;gt;();&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;&amp;nbsp;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;    &lt;span style="color:#008000;"&gt;// brute force attack to set my own factory via reflection&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;    var fieldInfo = &lt;span style="color:#0000ff;"&gt;typeof&lt;/span&gt;(UnitOfWork).GetField(&lt;span style="color:#006080;"&gt;&amp;quot;_unitOfWorkFactory&amp;quot;&lt;/span&gt;,&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;        BindingFlags.Static | BindingFlags.SetField | BindingFlags.NonPublic);&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;    fieldInfo.SetValue(&lt;span style="color:#0000ff;"&gt;null&lt;/span&gt;, _factory);&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;&amp;nbsp;&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;    _mocks.BackToRecordAll();&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;    SetupResult.For(_factory.Create()).Return(_unitOfWork);&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;    SetupResult.For(_factory.CurrentSession).Return(_session);&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;"&gt;    _mocks.ReplayAll();&lt;/pre&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;line-height:12pt;font-family:consolas,&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;"&gt;}&lt;/pre&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;That&amp;#39;s all we need for the moment regarding the UnitOfWork class. Next topics 
will be the the implementation of the UnitOfWorkFactory class and then of the 
UnitOfWorkImplementor class. The details will be presented in the next post to 
this blog. So keep ready...&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Part 2&lt;/p&gt;
&lt;h2&gt;Design and Implementation&lt;/h2&gt;
&lt;h3&gt;The Unit Of Work Factory&lt;/h3&gt;
&lt;p&gt;The creation of a unit of work instance is a complex process and as such is a 
good candidate for a factory.&lt;/p&gt;
&lt;p&gt;Since a UoW (Unit of Work) is basically a wrapper around a NHibernate session 
object I&amp;#39;ll need to open such a session whenever I start a new UoW. But to be 
able to get such a session NHibernate has to be configured and a NHibernate 
Session Factory has to be available. The interface of my UoW factory is defined 
as follows&lt;/p&gt;
&lt;p&gt;&lt;a&gt;&lt;img style="border-width:0px;" alt="image" border="0" height="236" width="214" /&gt;&lt;/a&gt; &lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;</description></item></channel></rss>
