The ‘Add Opponent’ button is located within a Backbone.Marionette.ItemView named List.PanelView. When the button is clicked there is a add opponent form to replace the list of opponents.

List Opponent

It looks something like

Add Opponent

Here are the steps to make this happen. Have a view that is something like this


List.PanelView = Backbone.Marionette.ItemView.extend({

template: "#opponent-list-panel",
events: {
"click button.js-add": "addClicked"
},

addClicked: function (e) {
e.stopPropagation();
this.trigger("opponent:add");
}
});

Line 5 sets up an event to watch for a button click. When the button is click a call to trigger the “opponent.add” notification is made. In the controller during view instantiation, subscribe to the “opponent:add” notification on the instance of PanelView.


panelView.on("opponent:add", function () {
TournamentApp.vent.trigger("opponent:add");
});

This triggers another event notification to the parent of the controller/view pairing. Have the parent subscribe to this notification.


TournamentApp.module("OpponentsApp", function (OpponentsApp, TournamentApp) {
OpponentsApp.Router = Backbone.Marionette.AppRouter.extend({
appRoutes: {
"opponents": "listOpponents"
}
});

var API = {
listOpponents: function () {
OpponentsApp.List.Controller.listOpponents();
},

newOpponent: function () {
OpponentsApp.Add.Controller.addOpponent();
}
};

TournamentApp.vent.on("opponent:add", function () {
API.newOpponent();
});

TournamentApp.addInitializer(function () {
new OpponentsApp.Router({
controller: API
});
});
});

Lines 18 – 20 set up the “opponent:add” subscribe and respond by calling API.newOpponent(). This calls the OpponentsApp.Add.Controller.addOpponent().


TournamentApp.module("OpponentsApp.Add", function (Add, TournamentApp) {
Add.Controller = {
addOpponent: function () {
var opponent = TournamentApp.request("new:opponent:entity");
var newOpponentView = this.getNewOpponentView(opponent);
TournamentApp.mainRegion.show(newOpponentView);
},

getNewOpponentView: function (opponent) {
return new Add.AddForm({ model: opponent });
}
};
})

Finally the add opponent form is rendered where the list use to be.

I’m back to learning new skills so blogging what I learn guarantees that I know where to find it later. I built a new computer since I last was blogging and I’m just now getting things installed.

I installed Windows Live Writer without difficulty but I had to download the whole Windows Essentials to get it.

I’ve installed the Insert Code and will try it out below. First is javascript.

/ <span class="kwrd">this</span> <span class="kwrd">is</span> a model of a person
RobBackbone.Person = Backbone.Model.extend({
    url: <span class="kwrd">function</span>() {
        <span class="kwrd">return</span> <span class="str">&quot;/Home/Save/&quot;</span> + <span class="kwrd">this</span>;
    }
});

<span class="rem">// this is a collection of person models</span>
RobBackbone.PersonCollection = Backbone.Collection.extend({
    model: RobBackbone.Person,
    url: <span class="str">&quot;/Home/People&quot;</span>
});
Second is C#
<span class="kwrd">public</span> <span class="kwrd">class</span> EmbeddedController : Controller {
        <span class="rem">// This is the document store and is a singleton</span>
        <span class="kwrd">private</span> <span class="kwrd">static</span> IDocumentStore documentStore;

        <span class="kwrd">public</span> <span class="kwrd">new</span> IDocumentSession Session { get; set; }

        <span class="rem">/// &lt;summary&gt;</span>
        <span class="rem">/// Test for the document store and return it</span>
        <span class="rem">/// Otherwise, create a singleton document store</span>
        <span class="rem">/// &lt;/summary&gt;</span>
        <span class="kwrd">public</span> <span class="kwrd">static</span> IDocumentStore DocumentStore {
            get {
                <span class="kwrd">if</span>(documentStore != <span class="kwrd">null</span>) {
                    <span class="kwrd">return</span> documentStore;
                }
                <span class="kwrd">lock</span>(<span class="kwrd">typeof</span>(EmbeddedController)) {
                    documentStore = <span class="kwrd">new</span> EmbeddableDocumentStore {RunInMemory = <span class="kwrd">true</span>}.Initialize();
                }
                <span class="kwrd">return</span> documentStore;
            }
        }

        <span class="rem">/// &lt;summary&gt;</span>
        <span class="rem">/// Create the session as the controller action is being called</span>
        <span class="rem">/// &lt;/summary&gt;</span>
        <span class="rem">/// &lt;param name=&quot;filterContext&quot;&gt;&lt;/param&gt;</span>
        <span class="kwrd">protected</span> <span class="kwrd">override</span> <span class="kwrd">void</span> OnActionExecuting(ActionExecutingContext filterContext) { Session = DocumentStore.OpenSession(); }

        <span class="rem">/// &lt;summary&gt;</span>
        <span class="rem">/// If all is okay then save any changes as the controller action is being completed</span>
        <span class="rem">/// &lt;/summary&gt;</span>
        <span class="rem">/// &lt;param name=&quot;filterContext&quot;&gt;&lt;/param&gt;</span>
        <span class="kwrd">protected</span> <span class="kwrd">override</span> <span class="kwrd">void</span> OnActionExecuted(ActionExecutedContext filterContext) {
            <span class="kwrd">using</span>(Session) {
                <span class="kwrd">if</span>(Session != <span class="kwrd">null</span> &amp;&amp; filterContext.Exception == <span class="kwrd">null</span>) {
                    Session.SaveChanges();
                }
            }
        }
    }

Third is SQL

<span class="rem">-- MySQL Administrator dump 1.4</span>
<span class="rem">--</span>
<span class="rem">-- ------------------------------------------------------</span>
<span class="rem">-- Server version    5.0.67-community-nt</span>


/*!40101 <span class="kwrd">SET</span> @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
/*!40101 <span class="kwrd">SET</span> @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
/*!40101 <span class="kwrd">SET</span> @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
/*!40101 <span class="kwrd">SET</span> <span class="kwrd">NAMES</span> utf8 */;

/*!40014 <span class="kwrd">SET</span> @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0 */;
/*!40014 <span class="kwrd">SET</span> @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */;
/*!40101 <span class="kwrd">SET</span> @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE=<span class="str">'NO_AUTO_VALUE_ON_ZERO'</span> */;


<span class="rem">--</span>
<span class="rem">-- Create schema --</span>

<span class="kwrd">CREATE</span> <span class="kwrd">DATABASE</span> <span class="kwrd">IF</span> <span class="kwrd">NOT</span> <span class="kwrd">EXISTS</span> ;
<span class="kwrd">USE</span> ;

<span class="rem">--</span>
<span class="rem">-- Definition of table `bettype`</span>
<span class="rem">--</span>

<span class="kwrd">DROP</span> <span class="kwrd">TABLE</span> <span class="kwrd">IF</span> <span class="kwrd">EXISTS</span> `bettype`;
<span class="kwrd">CREATE</span> <span class="kwrd">TABLE</span> `bettype` (
  `BetTypeID` <span class="kwrd">int</span>(10) unsigned <span class="kwrd">NOT</span> <span class="kwrd">NULL</span> auto_increment,
  `BetTypeTitle` <span class="kwrd">varchar</span>(45) <span class="kwrd">character</span> <span class="kwrd">set</span> latin1 <span class="kwrd">NOT</span> <span class="kwrd">NULL</span>,
  `BetTypeDescription` <span class="kwrd">varchar</span>(500) <span class="kwrd">character</span> <span class="kwrd">set</span> latin1 <span class="kwrd">NOT</span> <span class="kwrd">NULL</span>,
  <span class="kwrd">PRIMARY</span> <span class="kwrd">KEY</span>  (`BetTypeID`)
) ENGINE=InnoDB AUTO_INCREMENT=3 <span class="kwrd">DEFAULT</span> CHARSET=utf8;

Fourth is HTML.

<span class="kwrd">&lt;!</span><span class="html">DOCTYPE</span> <span class="attr">html</span><span class="kwrd">&gt;</span>
<span class="kwrd">&lt;</span><span class="html">html</span><span class="kwrd">&gt;</span>
<span class="kwrd">&lt;</span><span class="html">head</span><span class="kwrd">&gt;</span>
    <span class="kwrd">&lt;</span><span class="html">meta</span> <span class="attr">charset</span><span class="kwrd">=&quot;utf-8&quot;</span> <span class="kwrd">/&gt;</span>
    <span class="kwrd">&lt;</span><span class="html">title</span><span class="kwrd">&gt;</span>@ViewBag.Title<span class="kwrd">&lt;/</span><span class="html">title</span><span class="kwrd">&gt;</span>
    <span class="kwrd">&lt;</span><span class="html">link</span> <span class="attr">href</span><span class="kwrd">=&quot;@Url.Content(&quot;</span>~/<span class="attr">Content</span>/<span class="attr">Site</span>.<span class="attr">css</span><span class="kwrd">&quot;)&quot;</span> <span class="attr">rel</span><span class="kwrd">=&quot;stylesheet&quot;</span> <span class="attr">type</span><span class="kwrd">=&quot;text/css&quot;</span> <span class="kwrd">/&gt;</span>
    <span class="kwrd">&lt;</span><span class="html">link</span> <span class="attr">href</span><span class="kwrd">=&quot;@Url.Content(&quot;</span>~/<span class="attr">public</span>/<span class="attr">css</span>/<span class="attr">bootstrap</span>.<span class="attr">css</span><span class="kwrd">&quot;)&quot;</span> <span class="attr">rel</span><span class="kwrd">=&quot;stylesheet&quot;</span> <span class="attr">type</span><span class="kwrd">=&quot;text/css&quot;</span> <span class="kwrd">/&gt;</span>
    <span class="kwrd">&lt;</span><span class="html">link</span> <span class="attr">href</span><span class="kwrd">=&quot;@Url.Content(&quot;</span>~/<span class="attr">public</span>/<span class="attr">css</span>/<span class="attr">bootstrap-responsive</span>.<span class="attr">css</span><span class="kwrd">&quot;)&quot;</span> <span class="attr">rel</span><span class="kwrd">=&quot;stylesheet&quot;</span> <span class="attr">type</span><span class="kwrd">=&quot;text/css&quot;</span> <span class="kwrd">/&gt;</span>
    <span class="kwrd">&lt;</span><span class="html">link</span> <span class="attr">href</span><span class="kwrd">=&quot;@Url.Content(&quot;</span>~/<span class="attr">public</span>/<span class="attr">css</span>/<span class="attr">overrides</span>.<span class="attr">css</span><span class="kwrd">&quot;)&quot;</span> <span class="attr">rel</span><span class="kwrd">=&quot;stylesheet&quot;</span> <span class="attr">type</span><span class="kwrd">=&quot;text/css&quot;</span> <span class="kwrd">/&gt;</span>
    <span class="kwrd">&lt;</span><span class="html">script</span> <span class="attr">src</span><span class="kwrd">=&quot;@Url.Content(&quot;</span>~/<span class="attr">Scripts</span>/<span class="attr">jquery-1</span>.<span class="attr">7</span>.<span class="attr">2</span>.<span class="attr">min</span>.<span class="attr">js</span><span class="kwrd">&quot;)&quot;</span> <span class="attr">type</span><span class="kwrd">=&quot;text/javascript&quot;</span><span class="kwrd">&gt;&lt;/</span><span class="html">script</span><span class="kwrd">&gt;</span>
    &lt;script src=<span class="str">&quot;@Url.Content(&quot;</span>~/Scripts/underscore.js<span class="str">&quot;)&quot;</span> type=<span class="str">&quot;text/javascript&quot;</span>&gt;&lt;/script&gt;
    &lt;script src=<span class="str">&quot;@Url.Content(&quot;</span>~/Scripts/backbone.js<span class="str">&quot;)&quot;</span> type=<span class="str">&quot;text/javascript&quot;</span>&gt;<span class="kwrd">&lt;/</span><span class="html">script</span><span class="kwrd">&gt;</span>
<span class="kwrd">&lt;/</span><span class="html">head</span><span class="kwrd">&gt;</span>

<span class="kwrd">&lt;</span><span class="html">body</span><span class="kwrd">&gt;</span>
    @RenderBody()
<span class="kwrd">&lt;/</span><span class="html">body</span><span class="kwrd">&gt;</span>
<span class="kwrd">&lt;/</span><span class="html">html</span><span class="kwrd">&gt;</span>
<span class="kwrd">The only way to see if the code embedding works is to post it.</span>

I had to write a sproc to modify a XML column in a MS SQL Server database. There is a lot of information out in the Google but I found most of it misleading.

 

Here are a few of the better sites:

 

The XML column was introduced with SQL Server 2005 and this is an article that goes over the basics.

http://www.codeguru.com/csharp/.net/net_data/article.php/c19491/SQL-Server-2005-XQuery-and-XMLDML–Part-1.htm

 

Here the official MS site for XML Data Modification Language (XML DML)

http://msdn.microsoft.com/en-us/library/ms177454

 

Finally here is a site that goes over most of the XML methods.

http://www.simple-talk.com/sql/learn-sql-server/the-xml-methods-in-sql-server/

 

My task was to modify an existing XML configuration file that was saved into a XML column in the table. I ended up using .modify with insert to add new elements. The main problem I had was understanding the syntax.

 

The modification was similar to this:

 

<celsiusAliases>

<alias>C</alias>

</celsiusAliases>

<fahrenheitAliases>

<alias>F</alias>

</fahrenheitAliases>

 

In order to add this modification I declared a variable, @newAliases, as a XML SQL type.

 

declare @newAliases xml

set @newAliases = ‘<celsiusAliases><alias>C</alias></celsiusAliases><fahrenheitAliases><alias>F</alias></fahrenheitAliases>’

 

The next step is to make the modifications in the correct element of the XML file by using the update/modify syntax of xquery/xpath.

 

update [HydraConfig].[dbo].[HospitalPreferences]

set [ConfigFile].modify(‘declare default element namespace “http://p1s.com/mps/2010/XMLSchema”;

insert sql:variable(“@newAliases”) as last into (/hospital/sentri7/preferences/creat)[1]’)

where Id=@min

 

I have bolded some of the more interesting syntax. As you can see this is an update SQL statement with the xquery modify. I used insert to add the new aliases. The 2 other choices besides insert are delete and replace value of

 

Notice the a part of the modify method has declare default element namespace http://p1s.com/mps/2010/XMLSchema. You have to declare the namespace in order to make this modification work. This is especially true if you have nested namespaces.

 

Insert takes the new node (@newAliases) as Expression1 and identifies the singleton node that is relative to the insert as Expression2.

 

The syntax is:

 

insert

Expression1 (

{as first | as last} into | after | before

Expression2

)

 

What (/hospital/sentri7/preferences/creat)[1] means is follow the elements:

 

<hospital>

<sentri7>

<preferences>

<creat>

 

And add the

 

<celsiusAliases>

<alias>C</alias>

</celsiusAliases>

<fahrenheitAliases>

<alias>F</alias>

</fahrenheitAliases>

 

As the last element of the <creat> element. The [1] is the first occurrence of the creat element. This is not zero-based.

There are a number of needed infrastructure pieces in order to effectively work with a team of developers and stakeholders. If you’re using a technique like lean and want to provide CI (continuous integration) along with a Kanban board then you can use web sites that provide this infrastructure.

Scott Hanselman  gave a talk at an OreDev in November 2009 titled, “Information Overload and Managing the Flow” that discusses some web sites for all the information that you receive on a daily basis. While his talk was specific to managing information the point is that there are free web sites for doing this.

Free is good but for a team it is no longer free. The free part is more geared for a single person working on a single project. This is ideal for trying out the web site and actually doing a small project.

What types of web sites would I use? For a team you need a few different web sites because I haven’t been able to locate an all-in-one web site that provides everything. If the team is going to be using a short iteration cycle approach and having the work exposed to the stakeholders you need to have four main areas covered.

You need some where to manage the short iteration cycles of the project. There are several ways to do this and for this discussion I will be using the Kanban approach. A web site I like is Agile Zen. The plan that fits best happens to be the most popular. This is the PRO plan at $29/month. It allows 10 projects, 10 collaborators, 10GB of file storage with email and IM notification and SSL encryption. This works good with a 3 person team and a few stakeholders.

The next area is you need somewhere to put the source code. The web site I like is Unfuddle. The thing I like about this web site is you can use either SVN or Git. The plan that I like is the Compact plan because it is the first plan to allow SSL. You really don’t want to be sending your code unencrypted. The plan provides 2GB of storage and 10 active projects for 20 people. In addition you get a dashboard, milestones and bug tracking.

So with source control and project management in place you now need a place to host the work. I currently use a hosting site for this blog but I don’t like the idea of using it to host the project. The reason is I want complete control of the project and many hosting web site charge more money for complete control. You can’t blame them because if you have control then you need to be hosted on dedicated server and not sharing a server. So I looked into cloud hosting. I haven’t made up my mind on what I want here. I’m mulling over two directions to take.

The first is using something like Amazon’s EC2. This service provides a resizable computing capacity in the cloud. Basically Amazon provides you with a server in the cloud.

The second option I’m considering is to use a VMWare hosting site. What this allows is a server that will have a VMWare image that can be used to deploy new web servers by deploying a new VMWare image. I like this and it may be the way I’ll go.

The important thing about a hosting site is that I have access to a database, preferably MS SQL Server. So no matter what way I decide I’ll need a db.

The last thing to consider is continuous integration. There are a couple of CI applications that I like, Hudson and TeamCity. Hudson it a java based application that runs in Tomcat and is built with a plug-in architecture. TeamCity is a CI and build management system offered by JetBrains (maker of ReSharper). What I really want is to get it free and put it on the hosting site.

That basically covers what I need have in place for a team developed project. There are other web sites to handle some of the things covered by Scott Hanselman and they may be needed too. These four areas address the infrastructure needs I have for team development.

This is fairly easy if you know the special sauce for encrypting Asp.Net web.config. You can use the built in functionality of Asp.Net. Go to Start => All Programs => Microsoft Visual Studio 2005/2008 => Visual Studio Tools =>Microsoft Visual Studio 2005/2008 Command Prompt.

Type in the following command (for using IIS):

aspnet_regiis.exe -pe "connectionString" -app "/<my virtual directory>"

You should see ‘Encrypting configuration section…" followed by "Succeeded!"

That is the first half. You then need to execute a second command to prevent, "Failed to decrypt using provider ‘RsaProtectedConfigurationProvider’. Error message from the provider: The RSA key container could not be opened".

aspnet_regiis.exe -pa "NetFrameworkConfigurationKey" "ASPNET"

You should see "Adding ACL for access to the RSA Key container…" followed by "Suceeded!"

Here are the two web sites I used to find this:

How to Encrypt connection string in web.config

Encrypting configuration files using protected configuration

Here is an interesting tidbit on using the lazy and outer-join property in Set mapping. A Set is a collection of unique items and is optimized for reading and writing. When using Set remember to assign a data type of HashSet in your class.

The lazy property is by default is set to true. If your code does a session.Get<T> and uses a foreach loop on the Set NHibernate will generate two select statements. Even if you change the lazy property to false you still get two select statements because NHibernate does not control how the Set is loaded. NHibernate in order to avoid the possibility of a Cartesian product generates the two select statements.

When the lazy property is false the Set is loaded when the .Get<T> is called. When the lazy property is set to true then the collection will only be loaded in the foreach loop.

If you want to load both the entity and the Set is a single SQL statement then you must use the outer-join property set to true. However, this is an expensive operations if you only need the Set loaded for certain situations. It is recommended that you don’t set the outer-join property to true.

What should you do? You should manage this at a higher level and not in the mapping. If you need all of the records in a Set to be loaded with the entity then you would use .SetFetchMode as part of your query. This would look something like this:

var myEntity = session.CreateCriteria<T>().SetFetchMode("U",FetchMode.Join).List();

where <T> is the class and U is the Set within the class.

This site is a screencast site that actually contains valuable information. I’m not saying that screencasts like Summer of NHibernate don’t have value. Summer of NHibernate is an excellent source for information for a good introduction to NHibernate.

What I like about TekPub is that use of domain experts on the subject. For Mastering NHibernate Rob Conery enlists the help of Oren Eini to dive much deeper into the material.

As the owners of the site put it, "Techbooks pretty much suck most of the time and you end up spending a whole mess of money when really what you want is to spend less time (and money) and learn from the people you trust."

If you’re looking for some excellent material then I urge you to check out TekPub.

I have Google’d this and tried to find an answer to this error message for weeks.  I got a Error with controller lot of hits from Google but I couldn’t find the definitive answer to correct the error. I’m using Rhino.Commons as part of the application along with Castle project and NHibernate.

So I started a solution from scratch adding the stack components as I went. I got Castle IoC and MonoRail displaying a simple page. I added the Spark View Engine and still got the home/index.spark page to render. When I added the Rhino.Commons components that is when I got the error. That is when I finally had the ‘aha’ moment. All of the Google hits never gave me any real clue about what the problem was. Here is the definitive solution to the problem.

Once Rhino.Commons along with the IoC class is introduced you need to register the controllers. I never put this rather obvious conclusion in place because I wasn’t thinking it was caused by the Rhino.Commons IoC class. I kept looking at the web.config file and the controllers that were being registered there.

Here is how I registered the controller by placing this in the global.asax.cs file.

IoC.Container.Register(
                AllTypes.Of<IController>().FromAssemblyNamed("your controllers"));

All of my controllers extend SmartDispatcherController.

What directory structure should be used for a web based project? There are no hard, Application Structure fast rules for this. The opinions vary and even my typical website project has changed. This is the latest project directory organization that I am using.

There are three projects: Genealogist, Genealogist.Tests and Genealogist.Web. Genealogist.Web is an Add => New Project => Visual C# => Web => ASP.NET Web Application. Don’t use Add => New Web Site => ASP.NET Web Site. This will not play well with the Global.asax/Global.asax.cs file. The other two are just C# class library projects.

The Genealogist.Web application has a special directory, FrameStack. FrameStack itself has three directories: NHibernate, Spark and Windsor. All three have a class named ConfigurationByConvention. As the name implies each of these classes provide methods for configuring the 3rd party libraries without using .XML files.

The Genealogist project has two directories: DomainModel and Queries. More directories may be added in the future as the project is developed. For now YAGNI indicates that this is the minimum of what is needed.

The DomainModel is based on using DDD principles and the entities, value objects, factories and repositories will be created there. The Queries directory is something I added after reading Udi Dahan’s Employing the Domain Model Pattern in MSDN Magazine. It is a separation of read-only query support from the full CRUD requirements found in the DomainModel.

Web References The 3rd party DLLs I used are from the Castle, NHibernate and Spark View Engine open source projects. I’ll add the Rhino.Commons and Fluent NHibernate when I start developing the Domain Model.

Anyway this is my current web site application structure. It uses Castle Windsor and MonoRail along with the Spark View Engine.

I have played with three different approaches to configuring Rhino.Commons, NHibernate and Windsor container for unit testing. I’ve spiked these three flavors in order to investigate building an infrastructure that is open to extension but closed to modification. I’m still in the process of doing my analysis but I now have 3 approaches to  play with.

My last blog entry showed how to use Rhino.Commons with an in memory SQLite database. The example also used Windsor container and it was my initial proof of concept. There are lots of blogs like this but I still had trouble figuring out how to make this rather easy approach work.

Since then I have been refactoring this approach and making it more closely follow the Open-Closed Principle first coined in 1988 by Bertrand Meyer in his book, Object-Oriented Software Construction. Prentice Hall. ISBN 0136290493. There is a very good article on the ObjectMentor blog about the OCP.

The first refactor I did was move away from using the hibernate.cfg.xml file and do it NHibernate configuration dynamically. I did this by creating a ConventionConfiguration class that uses NHibernate.Cfg.Environment static class properties.

<span class="kwrd">using</span> NHibernate;
<span class="kwrd">using</span> Rhino.Commons;
<span class="kwrd">using</span> Configuration = NHibernate.Cfg.Configuration;
<span class="kwrd">using</span> Environment=NHibernate.Cfg.Environment;

<span class="kwrd">namespace</span> CrawBuck.Commons.NHibernate {
    <span class="kwrd">public</span> <span class="kwrd">class</span> ConventionConfiguration : Configuration {
        <span class="kwrd">private</span> <span class="kwrd">readonly</span> Configuration configuration = <span class="kwrd">new</span> Configuration();

        <span class="kwrd">public</span> Configuration getConfiguration() { <span class="kwrd">return</span> configuration; }

        <span class="rem">/// &lt;summary&gt;</span>
        <span class="rem">/// This is the wiring up point for NHibernate. This sets up the Environment properties for</span>
        <span class="rem">/// SQLite in memory database</span>
        <span class="rem">/// &lt;/summary&gt;</span>
        <span class="kwrd">public</span> <span class="kwrd">void</span> ConfigureNHiberateForSQLite() {
            IDictionary&lt;<span class="kwrd">string</span>, <span class="kwrd">string</span>&gt; properties = <span class="kwrd">new</span> Dictionary&lt;<span class="kwrd">string</span>, <span class="kwrd">string</span>&gt;();
            properties.Add(Environment.ConnectionProvider, <span class="str">&quot;NHibernate.Connection.DriverConnectionProvider&quot;</span>);
            properties.Add(Environment.ConnectionDriver, <span class="str">&quot;NHibernate.Driver.SQLite20Driver&quot;</span>);
            properties.Add(Environment.ConnectionString, <span class="str">&quot;Data Source=:memory:;Version=3;New=True;&quot;</span>);
            properties.Add(Environment.ShowSql, <span class="str">&quot;true&quot;</span>);
            properties.Add(Environment.Dialect, <span class="str">&quot;NHibernate.Dialect.SQLiteDialect&quot;</span>);
            properties.Add(Environment.ReleaseConnections, <span class="str">&quot;on_close&quot;</span>);
            properties.Add(Environment.ProxyFactoryFactoryClass, <span class="str">&quot;NHibernate.ByteCode.Castle.ProxyFactoryFactory, NHibernate.ByteCode.Castle&quot;</span>);
            configuration.SetProperties(properties);
        }
    }
}

This class will only do two things right now. It will dynamically configure NHibernate to use SQLite and it will return the NHibernate.Cfg.Configuration variable that holds these properties. For my infrastructure work I will later add a method to dynamically configure MS SQL Server database. Unit testing should be fast but there are times when you actually have to hit a real database. I call real database testing ‘integration database testing’ and don’t have my continuous integration build machine run this type of testing at check in. I do want to do integration database testing but I set the build for this to happen at about 4 hour intervals. Currently I’m using CruiseControl.NET but I’m going to be moving to Hudson.

The next change I made was to move the configuration of the Windsor container to a class of its own, BinsorlessUnitOfWorkApplication. This is an extension of Rhino.Commons.HttpModules.UnitOfWorkApplication.

<span class="kwrd">using</span> System;
<span class="kwrd">using</span> Castle.Facilities.FactorySupport;
<span class="kwrd">using</span> Castle.MicroKernel.Registration;
<span class="kwrd">using</span> Castle.Windsor;
<span class="kwrd">using</span> NHibernate;
<span class="kwrd">using</span> NHibernate.Cfg;
<span class="kwrd">using</span> Rhino.Commons;
<span class="kwrd">using</span> Rhino.Commons.HttpModules;
<span class="kwrd">using</span> Environment=System.Environment;

<span class="kwrd">namespace</span> CrawBuck.Commons.HttpModules {
    <span class="kwrd">public</span> <span class="kwrd">class</span> BinsorlessUnitOfWorkApplication : UnitOfWorkApplication {
        <span class="kwrd">protected</span> <span class="kwrd">override</span> IWindsorContainer CreateContainer(<span class="kwrd">string</span> windsorConfig) {
            <span class="rem">//ignore windsor config string and create it empty...</span>
            <span class="kwrd">return</span> <span class="kwrd">new</span> RhinoContainer();
        }

        <span class="rem">/// &lt;summary&gt;</span>
        <span class="rem">/// This wires up the IoC Rhino/Windsor container for the basic facilities and components.</span>
        <span class="rem">/// &lt;/summary&gt;</span>
        <span class="kwrd">public</span> <span class="kwrd">virtual</span> <span class="kwrd">void</span> InitializeContainer() {
            Environment.CurrentDirectory = AppDomain.CurrentDomain.BaseDirectory;
            IoC.Initialize(<span class="kwrd">new</span> WindsorContainer());
            IoC.Container
                .AddFacility&lt;FactorySupportFacility&gt;(<span class="str">&quot;factory.support&quot;</span>)
                .AddFacility&lt;RhinoTransactionFacility&gt;(<span class="str">&quot;transaction&quot;</span>)
                .Register(
                Component.For(<span class="kwrd">typeof</span>(IRepository&lt;&gt;)).ImplementedBy(<span class="kwrd">typeof</span>(NHRepository&lt;&gt;)),
                Component.For&lt;IUnitOfWorkFactory&gt;().ImplementedBy&lt;NHibernateUnitOfWorkFactory&gt;());
        }

        <span class="kwrd">public</span> <span class="kwrd">void</span> RegisterSessionFactory(Configuration configuration) {
            (IoC.Resolve&lt;IUnitOfWorkFactory&gt;() <span class="kwrd">as</span> NHibernateUnitOfWorkFactory).RegisterSessionFactory(configuration, configuration.BuildSessionFactory());
        }

        <span class="kwrd">public</span> ISessionFactory GetUnitOfWorkFactory() {
            <span class="kwrd">return</span> (IoC.Resolve&lt;IUnitOfWorkFactory&gt;() <span class="kwrd">as</span> NHibernateUnitOfWorkFactory).NHibernateSessionFactory;
        }
    }
}

I had to override the CreateContainer method in Rhino.Commons.HttpModules.UnitOfWork class to remove the need for the windsor.boo file. Once these two classes were in place I refactored the code from my last blog.

<span class="kwrd">using</span> System;
<span class="kwrd">using</span> System.Reflection;
<span class="kwrd">using</span> CrawBuck.Commons.HttpModules;
<span class="kwrd">using</span> CrawBuck.Commons.NHibernate;
<span class="kwrd">using</span> CrawBuck.Commons.Tests.Repository.Domain;
<span class="kwrd">using</span> NHibernate.Criterion;
<span class="kwrd">using</span> NHibernate.Tool.hbm2ddl;
<span class="kwrd">using</span> NUnit.Framework;
<span class="kwrd">using</span> Rhino.Commons;

<span class="kwrd">namespace</span> CrawBuck.Commons.Tests.Repository {
    [TestFixture]
    <span class="kwrd">public</span> <span class="kwrd">class</span> RhinoCommonsUnitOfWork {
        <span class="kwrd">protected</span> BinsorlessUnitOfWorkApplication unitOfWorkApplication = <span class="kwrd">new</span> BinsorlessUnitOfWorkApplication();
        <span class="kwrd">protected</span> ConventionConfiguration cc = <span class="kwrd">new</span> ConventionConfiguration();

        [SetUp]
        <span class="kwrd">public</span> <span class="kwrd">void</span> SetUp() {
            unitOfWorkApplication.InitializeContainer();
            cc.ConfigureNHiberateForSQLite();
            cc.getConfiguration().AddAssembly(Assembly.GetExecutingAssembly());
            unitOfWorkApplication.RegisterSessionFactory(cc.getConfiguration());
        }

        [Test]
        <span class="kwrd">public</span> <span class="kwrd">void</span> CanStartUnitOfWorkTest() {
            Customer customer = <span class="kwrd">new</span> Customer(<span class="str">&quot;Alan&quot;</span>, <span class="str">&quot;Buck&quot;</span>);
            Guid guid = customer.Id;
            <span class="kwrd">using</span>(IUnitOfWork uow = UnitOfWork.Start()) {
                uow.BeginTransaction();
                <span class="kwrd">new</span> SchemaExport(cc.getConfiguration()).Execute(<span class="kwrd">false</span>, <span class="kwrd">true</span>, <span class="kwrd">false</span>, <span class="kwrd">true</span>, UnitOfWork.CurrentSession.Connection, <span class="kwrd">null</span>);
                Repository&lt;Customer&gt;.Save(customer);
                uow.TransactionalFlush();
                Customer loadCustomer = Repository&lt;Customer&gt;.Load(guid);
                Assert.AreEqual(loadCustomer.FirstName, <span class="str">&quot;Alan&quot;</span>);
                Assert.AreEqual(loadCustomer.LastName, <span class="str">&quot;Buck&quot;</span>);
                DetachedCriteria criteria = DetachedCriteria.For(<span class="kwrd">typeof</span>(Customer)).Add(Restrictions.Eq(<span class="str">&quot;Id&quot;</span>, guid));
                Customer repositoryCustomer = Repository&lt;Customer&gt;.FindOne(criteria);
                Assert.AreEqual(repositoryCustomer.FirstName, <span class="str">&quot;Alan&quot;</span>);
                Assert.AreEqual(repositoryCustomer.LastName, <span class="str">&quot;Buck&quot;</span>);
            }
        }
    }
}

The following tests use either the Customer or Person classes.

<span class="kwrd">using</span> System;

<span class="kwrd">namespace</span> CrawBuck.Commons.Tests.Repository.Domain {
    <span class="kwrd">public</span> <span class="kwrd">class</span> Customer {
        <span class="kwrd">private</span> Guid id = Guid.NewGuid();
        <span class="kwrd">private</span> <span class="kwrd">string</span> firstName;
        <span class="kwrd">private</span> <span class="kwrd">string</span> lastName;

        <span class="kwrd">public</span> Customer() { }

        <span class="kwrd">public</span> Customer(<span class="kwrd">string</span> firstName, <span class="kwrd">string</span> lastName)
        {
            <span class="kwrd">this</span>.firstName = firstName;
            <span class="kwrd">this</span>.lastName = lastName;
        }
        <span class="kwrd">public</span> <span class="kwrd">virtual</span> Guid Id { get { <span class="kwrd">return</span> id; } set { id = <span class="kwrd">value</span>; } }
        <span class="kwrd">public</span> <span class="kwrd">virtual</span> <span class="kwrd">string</span> FirstName { get { <span class="kwrd">return</span> firstName; } set { firstName = <span class="kwrd">value</span>; } }
        <span class="kwrd">public</span> <span class="kwrd">virtual</span> <span class="kwrd">string</span> LastName { get { <span class="kwrd">return</span> lastName; } set { lastName = <span class="kwrd">value</span>; } }
    }
}
&lt;?xml version=<span class="str">&quot;1.0&quot;</span> encoding=<span class="str">&quot;utf-8&quot;</span> ?&gt;
&lt;hibernate-mapping <span class="kwrd">default</span>-lazy=<span class="str">'false'</span>
    assembly=<span class="str">'CrawBuck.Commons.Tests'</span>
    <span class="kwrd">namespace</span>=<span class="str">'CrawBuck.Commons.Tests.Repository.Domain'</span>
    xmlns=<span class="str">'urn:nhibernate-mapping-2.2'</span>&gt;
  &lt;<span class="kwrd">class</span> name=<span class="str">'Customer'</span>&gt;
    &lt;id name=<span class="str">&quot;Id&quot;</span> column=<span class="str">&quot;Id&quot;</span>&gt;
      &lt;generator <span class="kwrd">class</span>=<span class="str">&quot;assigned&quot;</span>/&gt;
    &lt;/id&gt;
    &lt;property name=<span class="str">&quot;FirstName&quot;</span> /&gt;
    &lt;property name=<span class="str">&quot;LastName&quot;</span>/&gt;
  &lt;/<span class="kwrd">class</span>&gt;
&lt;/hibernate-mapping&gt;<br />
<span class="kwrd">using</span> System;

<span class="kwrd">namespace</span> CrawBuck.Commons.Tests.Repository.Domain {
    <span class="kwrd">public</span> <span class="kwrd">class</span> Person {
        <span class="kwrd">private</span> Guid id = Guid.NewGuid();
        <span class="kwrd">private</span> <span class="kwrd">string</span> firstName;
        <span class="kwrd">private</span> <span class="kwrd">string</span> lastName;
        <span class="kwrd">private</span> <span class="kwrd">int</span> age;

        <span class="kwrd">public</span> Person() { }

        <span class="kwrd">public</span> Person(<span class="kwrd">string</span> firstName, <span class="kwrd">string</span> lastName, <span class="kwrd">int</span> age)
        {
            <span class="kwrd">this</span>.firstName = firstName;
            <span class="kwrd">this</span>.lastName = lastName;
            <span class="kwrd">this</span>.age = age;
        }

        <span class="kwrd">public</span> <span class="kwrd">virtual</span> Guid Id { get { <span class="kwrd">return</span> id; } set { id = <span class="kwrd">value</span>; } }
        <span class="kwrd">public</span> <span class="kwrd">virtual</span> <span class="kwrd">string</span> FirstName { get { <span class="kwrd">return</span> firstName; } set { firstName = <span class="kwrd">value</span>; } }
        <span class="kwrd">public</span> <span class="kwrd">virtual</span> <span class="kwrd">string</span> LastName { get { <span class="kwrd">return</span> lastName; } set { lastName = <span class="kwrd">value</span>; } }
        <span class="kwrd">public</span> <span class="kwrd">virtual</span> <span class="kwrd">int</span> Age { get { <span class="kwrd">return</span> age; } set { age = <span class="kwrd">value</span>; } }
    }
}
&lt;?xml version=<span class="str">&quot;1.0&quot;</span> encoding=<span class="str">&quot;utf-8&quot;</span> ?&gt;
&lt;hibernate-mapping <span class="kwrd">default</span>-lazy=<span class="str">'false'</span>
    assembly=<span class="str">'CrawBuck.Commons.Tests'</span>
    <span class="kwrd">namespace</span>=<span class="str">'CrawBuck.Commons.Tests.Repository.Domain'</span>
    xmlns=<span class="str">'urn:nhibernate-mapping-2.2'</span>&gt;
  &lt;<span class="kwrd">class</span> name=<span class="str">'Person'</span>&gt;
    &lt;id name=<span class="str">&quot;Id&quot;</span> column=<span class="str">&quot;Id&quot;</span>&gt;
      &lt;generator <span class="kwrd">class</span>=<span class="str">&quot;assigned&quot;</span>/&gt;
    &lt;/id&gt;
    &lt;property name=<span class="str">&quot;FirstName&quot;</span> /&gt;
    &lt;property name=<span class="str">&quot;LastName&quot;</span>/&gt;
    &lt;property name=<span class="str">&quot;Age&quot;</span> type=<span class="str">&quot;int&quot;</span>/&gt;
  &lt;/<span class="kwrd">class</span>&gt;
&lt;/hibernate-mapping&gt;

The next refactor was to create a test base class that will allow the configuration of both the Windsor container and NHibernate using SQLite to be used by any unit test class.

<span class="kwrd">using</span> System;
<span class="kwrd">using</span> System.Reflection;
<span class="kwrd">using</span> CrawBuck.Commons.HttpModules;
<span class="kwrd">using</span> CrawBuck.Commons.NHibernate;
<span class="kwrd">using</span> CrawBuck.Commons.Tests.Repository.Domain;
<span class="kwrd">using</span> NHibernate.Criterion;
<span class="kwrd">using</span> NHibernate.Tool.hbm2ddl;
<span class="kwrd">using</span> NUnit.Framework;
<span class="kwrd">using</span> Rhino.Commons;

<span class="kwrd">namespace</span> CrawBuck.Commons.Tests.Repository {
    [TestFixture]
    <span class="kwrd">public</span> <span class="kwrd">class</span> RhinoCommonsUnitOfWork {
        <span class="kwrd">protected</span> BinsorlessUnitOfWorkApplication unitOfWorkApplication = <span class="kwrd">new</span> BinsorlessUnitOfWorkApplication();
        <span class="kwrd">protected</span> ConventionConfiguration cc = <span class="kwrd">new</span> ConventionConfiguration();

        [SetUp]
        <span class="kwrd">public</span> <span class="kwrd">void</span> SetUp() {
            unitOfWorkApplication.InitializeContainer();
            cc.ConfigureNHiberateForSQLite();
            cc.getConfiguration().AddAssembly(Assembly.GetExecutingAssembly());
            unitOfWorkApplication.RegisterSessionFactory(cc.getConfiguration());
        }

        [Test]
        <span class="kwrd">public</span> <span class="kwrd">void</span> CanStartUnitOfWorkTest() {
            Customer customer = <span class="kwrd">new</span> Customer(<span class="str">&quot;Alan&quot;</span>, <span class="str">&quot;Buck&quot;</span>);
            Guid guid = customer.Id;
            <span class="kwrd">using</span>(IUnitOfWork uow = UnitOfWork.Start()) {
                uow.BeginTransaction();
                <span class="kwrd">new</span> SchemaExport(cc.getConfiguration()).Execute(<span class="kwrd">false</span>, <span class="kwrd">true</span>, <span class="kwrd">false</span>, <span class="kwrd">true</span>, UnitOfWork.CurrentSession.Connection, <span class="kwrd">null</span>);
                Repository&lt;Customer&gt;.Save(customer);
                uow.TransactionalFlush();
                Customer loadCustomer = Repository&lt;Customer&gt;.Load(guid);
                Assert.AreEqual(loadCustomer.FirstName, <span class="str">&quot;Alan&quot;</span>);
                Assert.AreEqual(loadCustomer.LastName, <span class="str">&quot;Buck&quot;</span>);
                DetachedCriteria criteria = DetachedCriteria.For(<span class="kwrd">typeof</span>(Customer)).Add(Restrictions.Eq(<span class="str">&quot;Id&quot;</span>, guid));
                Customer repositoryCustomer = Repository&lt;Customer&gt;.FindOne(criteria);
                Assert.AreEqual(repositoryCustomer.FirstName, <span class="str">&quot;Alan&quot;</span>);
                Assert.AreEqual(repositoryCustomer.LastName, <span class="str">&quot;Buck&quot;</span>);
            }
        }
    }
}

Here is a unit test class that takes advantage of the RepositoryTestsBase class.

<span class="kwrd">using</span> System;
<span class="kwrd">using</span> CrawBuck.Commons.Tests.ForTesting;
<span class="kwrd">using</span> CrawBuck.Commons.Tests.Repository.Domain;
<span class="kwrd">using</span> NHibernate;
<span class="kwrd">using</span> NHibernate.Criterion;
<span class="kwrd">using</span> NHibernate.Tool.hbm2ddl;
<span class="kwrd">using</span> NUnit.Framework;
<span class="kwrd">using</span> Rhino.Commons;

<span class="kwrd">namespace</span> CrawBuck.Commons.Tests.Repository {
    [TestFixture]
    <span class="kwrd">public</span> <span class="kwrd">class</span> RepositoryTest : RepositoryTestsBase {
        <span class="kwrd">private</span> ISession session;
        <span class="kwrd">private</span> Person person;
        <span class="kwrd">private</span> Guid guid;

        [TestFixtureSetUp]
        <span class="kwrd">public</span> <span class="kwrd">void</span> TestFixtureSetUp() {
            OneTimeTestInitialize();    
        }

        [SetUp]
        <span class="kwrd">public</span> <span class="kwrd">void</span> SetUp() {
            person = <span class="kwrd">new</span> Person(<span class="str">&quot;Alan&quot;</span>, <span class="str">&quot;Buck&quot;</span>, 62);
            guid = person.Id;
        }

        [Test]
        <span class="kwrd">public</span> <span class="kwrd">void</span> ShouldCreateRepositoryTest() {
            session = CreateSession();
            session.Save(person);
            session.Flush();
            session.Clear();
            Person loadPerson = session.Load&lt;Person&gt;(guid);
            Assert.AreEqual(loadPerson.FirstName, <span class="str">&quot;Alan&quot;</span>);
            Assert.AreEqual(loadPerson.LastName, <span class="str">&quot;Buck&quot;</span>);
            Assert.AreEqual(loadPerson.Age, 62);
            session.Dispose();
        }
        
        [Test]
        <span class="kwrd">public</span> <span class="kwrd">void</span> ShouldCreateUsingIRepositoryTest() {
            <span class="kwrd">using</span> (IUnitOfWork uow = UnitOfWork.Start()) {
                <span class="kwrd">new</span> SchemaExport(configuration).Execute(<span class="kwrd">false</span>, <span class="kwrd">true</span>, <span class="kwrd">false</span>, <span class="kwrd">true</span>, UnitOfWork.CurrentSession.Connection, <span class="kwrd">null</span>);
                Repository&lt;Person&gt;.Save(person);
                uow.TransactionalFlush();
                DetachedCriteria criteria = DetachedCriteria.For(<span class="kwrd">typeof</span>(Person)).Add(Restrictions.Eq(<span class="str">&quot;Id&quot;</span>, guid));
                Person loadPerson = Repository&lt;Person&gt;.FindOne(criteria);
                Assert.AreEqual(loadPerson.FirstName, <span class="str">&quot;Alan&quot;</span>);
                Assert.AreEqual(loadPerson.LastName, <span class="str">&quot;Buck&quot;</span>);
                Assert.AreEqual(loadPerson.Age, 62);
            }
        }

        [TearDown]
        <span class="kwrd">public</span> <span class="kwrd">void</span> TearDown() {}
    }
}

That covers two of the approaches to using Rhino.Commons, NHibernate and the Windsor container. The last approach is to use FluentNHibernate. I’m not using the ClassMap of FluentNHibernate. This still uses the .hbm.xml files.

<span class="kwrd">using</span> System;
<span class="kwrd">using</span> System.IO;
<span class="kwrd">using</span> System.Reflection;
<span class="kwrd">using</span> Castle.Windsor;
<span class="kwrd">using</span> CrawBuck.Commons.HttpModules;
<span class="kwrd">using</span> CrawBuck.Commons.NHibernate;
<span class="kwrd">using</span> CrawBuck.Commons.Tests.Repository.Domain;
<span class="kwrd">using</span> FluentNHibernate.AutoMap;
<span class="kwrd">using</span> FluentNHibernate.Cfg;
<span class="kwrd">using</span> FluentNHibernate.Cfg.Db;
<span class="kwrd">using</span> NHibernate;
<span class="kwrd">using</span> NHibernate.Criterion;
<span class="kwrd">using</span> NHibernate.Tool.hbm2ddl;
<span class="kwrd">using</span> NUnit.Framework;
<span class="kwrd">using</span> Rhino.Commons;
<span class="kwrd">using</span> Configuration = NHibernate.Cfg.Configuration;
<span class="kwrd">using</span> Environment=NHibernate.Cfg.Environment;

<span class="kwrd">namespace</span> CrawBuck.Commons.Tests.Repository {
    [TestFixture]
    <span class="kwrd">public</span> <span class="kwrd">class</span> FluentNHibernate {
        <span class="kwrd">private</span> <span class="kwrd">readonly</span> BinsorlessUnitOfWorkApplication unitOfWorkApplication = <span class="kwrd">new</span> BinsorlessUnitOfWorkApplication();
        <span class="kwrd">private</span> Configuration config;
        <span class="kwrd">private</span> <span class="kwrd">readonly</span> ConventionConfiguration cc = <span class="kwrd">new</span> ConventionConfiguration();

        [SetUp]
        <span class="kwrd">public</span> <span class="kwrd">void</span> SetUp() {
            unitOfWorkApplication.InitializeContainer();
            cc.ConfigureNHiberateForSQLite();
            config = cc.getConfiguration();
            config.AddAssembly(Assembly.GetExecutingAssembly());
            CreateRhinoSessionFactoryForSQLite();
        }

        [Test]
        <span class="kwrd">public</span> <span class="kwrd">void</span> CanStartUnitOfWorkTest() {
            Customer customer = <span class="kwrd">new</span> Customer(<span class="str">&quot;Alan&quot;</span>, <span class="str">&quot;Buck&quot;</span>);
            Guid guid = customer.Id;
            <span class="kwrd">using</span> (IUnitOfWork uow = UnitOfWork.Start()) {
                uow.BeginTransaction();
                <span class="kwrd">new</span> SchemaExport(config).Execute(<span class="kwrd">false</span>, <span class="kwrd">true</span>, <span class="kwrd">false</span>, <span class="kwrd">true</span>, UnitOfWork.CurrentSession.Connection, <span class="kwrd">null</span>);
                Repository&lt;Customer&gt;.Save(customer);
                uow.TransactionalFlush();
                Customer loadCustomer = Repository&lt;Customer&gt;.Load(guid);
                Assert.AreEqual(loadCustomer.FirstName, <span class="str">&quot;Alan&quot;</span>);
                Assert.AreEqual(loadCustomer.LastName, <span class="str">&quot;Buck&quot;</span>);
                DetachedCriteria criteria = DetachedCriteria.For(<span class="kwrd">typeof</span>(Customer)).Add(Restrictions.Eq(<span class="str">&quot;Id&quot;</span>, guid));
                Customer repositoryCustomer = Repository&lt;Customer&gt;.FindOne(criteria);
                Assert.AreEqual(repositoryCustomer.FirstName, <span class="str">&quot;Alan&quot;</span>);
                Assert.AreEqual(repositoryCustomer.LastName, <span class="str">&quot;Buck&quot;</span>);
            }
        }

        <span class="kwrd">private</span> <span class="kwrd">void</span> CreateRhinoSessionFactoryForSQLite() {
            IPersistenceConfigurer configurer = SQLiteConfiguration.Standard.InMemory().ShowSql();
            ISessionFactory sessionFactory = Fluently.Configure(config).Database(configurer).Mappings(m =&gt; m.FluentMappings.AddFromAssemblyOf&lt;Customer&gt;()).BuildSessionFactory();
            (Rhino.Commons.IoC.Resolve&lt;IUnitOfWorkFactory&gt;() <span class="kwrd">as</span> NHibernateUnitOfWorkFactory).RegisterSessionFactory(config, sessionFactory);
        }
    }
}

You will notice that I have a CreateRhinoSessionFactoryForSQLite method in this test class. It’s there because I’m lazy and it’s late. Maybe in a future blog I will refactor this unit test to use ClassMap and move the CreateRhinoSessionFactoryForSQLite to the BinsorlessUnitOfWorkApplication class. I’m still moving up the learning curve on FluentNHibernate and have only the basic understanding of what all this OSS project has to offer.

Next Page »