Using FluentNHibernate and Rhino-Commons – Part 2


In Using FluentNHibernate and Rhino-Commons – Part 1 I shared how to leverage INHibernateInitializationAware in order to get your FluentNHibernate configuration into the SessionFactory in your UnitOfWork.  In part 2 I’m going to show you how to do the same thing using the latest changes (r328) to FNH.

I was looking at the new FluentNHibernate site earlier and noticed (in the Wiki) that they added a new class called ‘Fluently’ to help assemble the NHibernate configuration.  The first thing that I noticed is that I needed to find a way to get the mappings into the Configuration that I am passing into the FluentNHibernateInitializationAwareConfigurator that I’ve been using.

Fluently.Configure().Mappings(m =>
  {
      m.FluentMappings.AddFromAssemblyOf<User>()
          .AlterConventions(convention =>
              {
                  convention.GetForeignKeyName = (prop => prop.Name + "Id");
                  convention.GetForeignKeyNameOfParent = (prop => prop.Name + "Id");
              }
          );
      m.Apply(cfg);
  });

This is actually a simplified version of what I am using, which is actually currently leveraging the AutoMapping features against entities in two different assemblies (although the example above is using FluentMapping).  I will probably create my own FluentMappings once the domain gels a bit more so that I can have more granular control over the database structure. 

However I decide to create my mappings (Fluent, Auto, classic HBM files, or a combination) I’ll still be able to use the Fluently class to apply them to the configuration as long as I remember to call Apply() and pass in the NHibernate Configuration that is passed into the Configured() method in my FluentNHibernateInitializationAwareConfigurator.

author: Rob Kitson | posted @ Thursday, February 19, 2009 1:44 AM | Feedback (0)

Using FluentNHibernate and Rhino-Commons


Since it's inception, I have been a big fan of FluentNHibernate.  I am also a big fan of Ayende's Rhino-Tools.

A project that I've been working on recently has given me the opportunity to trying to leverage both.  I wanted to use DatabaseTextFixtureBase from Rhino.Commons.ForTesting with FluentNHibernate to work on my integration tests.  The problem that I kept coming up against was the fact that FluentNHibernate works it's magic on the NHibernate configuration in the PersistenceModel class, and getting your hands on the NHibernate configuration once you call DatabaseTestFixtureBase.InitializeNHibernateAndIoC() Rhino.Commons works it's magic privately and you no longer have access to the NHibernate config (or not in a way that I could see). 

As it turns out, my last assumption was wrong.  I asked the Rhino-TOols list how I might go about accomplishing this integration and in as simple a response as I could have hoped, I got a 1-word word response from Ayende, "INHibernateInitializationAware" (and honestly, I'm glad that that was all the help that I got.)  It was a simple hint but it made me go back and look at everything all over again and I saw a bunch of stuff that I hadn't looked at before. And now I'm chuckling a bit over his post from this morning about Static vs. Dynamic Dependencies because when I was looking at the implementations of INHibernateInitializationAware that are in Rhino.Commons I didn't find one that helped me understand what it's purpose was (in his words about another class, "there's not a lot happening there").

As it turns out If you register an INHibernateInitializationAware service with the container, it will be picked up by the NHibernateUnitOfWorkTestContext when it calls CreatConfigs().  So that's what I did.

public class FluentNHibernateInitializationAwareConfigurator : INHibernateInitializationAware
{
    public void BeforeInitialization(){}
 
    public void Configured(Configuration cfg)
    {
        var persistenceModel = new PersistenceModel
                                   {
                                       Conventions =
                                       {
                                           GetForeignKeyName = (prop => prop.Name + "Id"),
                                           GetForeignKeyNameOfParent = (prop => prop.Name + "Id")
                                       }
                                   };
        persistenceModel.addMappingsFromAssembly(typeof(ClickMap).Assembly);
        persistenceModel.Configure(cfg);
    }
 
    public void Initialized(Configuration cfg, ISessionFactory sessionFactory){}
}

author: Rob Kitson | posted @ Monday, February 02, 2009 9:29 PM | Feedback (0)

Giving Evernote a Go


I've been looking for a good ubiquitous note taking application ever since I read that Microsoft OneNote had a mobile client that would sync with the desktop app whenever you did a local ActiveSync between your Windows Mobile SmartPhone and your PC.  After taking the time to install OneNote on my laptop and phone, I found out that when they said 'Sync' what they really meant was that any notes that you type into OneNote on your phone will be copied into a special section in OneNote on your desktop, and from there you can sort them into their appropriate categories.  All in all it felt clunky, so I never used it.

I took a step back and asked myself why I was disappointed and what features would make me happy.  I realized that the feature I've been looking for more than anything is the ability to access my notes from just about anywhere: My new work machine, my rapidly aging Dell Precision M90 development box at home, the family Mac Mini, one of the many laptops that the wife-to-be's newly formed company are using, or my new AT&T Tilt.  So, when I came across a post about Evernote on TechCrunch a few weeks ago, I decided to give it a go. 

The fat client has now been installed on all the machines where I spend more than a couple'a minutes per day.  I'm going to be shelving the Moleskine notebook for a few weeks to roll exclusively with Evernote to see how it works out.  I'll post a follow up at the end of the month, but in the mean time I may have a comment about it on Twitter.

author: Rob Kitson | posted @ Wednesday, April 09, 2008 1:27 AM | Feedback (0)

The new workstation at the day-job.


It just showed up on Monday and it screams!

64-bit Quad Core
4 GB RAM
3 15k drives

Wow!

Only problem is that we had to buy it through HP.  Putting together a similar box with parts from NewEgg would cost close to 1/3 what we paid... Ouch!

author: Rob Kitson | posted @ Wednesday, April 09, 2008 1:29 AM | Feedback (0)