tags:

views:

33

answers:

1

I am using the HybridSessionBuilder supplied by Palermo and his team .. link ..

We have our staging environments set up so that the url will be one of the following based on the environment

  • web-test.company.com
  • web-cert.company.com
  • web.company.com

what we normally do is take a look at the url and if it has "-test" we use the test configurations and so on (connection strings, etc).

This is the first project that uses nhibernate in this type of environment. What would be a good way to tell the Session Builder to use the correct hibernate cfg (I will build 1 for each environment).

The HybridSessionBuilder lives in an infrastructure layer and is injected into repositories via StructureMap.

+2  A: 

Here's how I select a single configuration file using the HybridSessionBuilder:

public Configuration GetConfiguration()
{
   var configuration = new Configuration();
   string cfgFile = Path.GetDirectoryName(Assembly.GetAssembly(this.GetType()).CodeBase) +
            "\\com.Data.nHibernate.cfg.xml";
   configuration.Configure(cfgFile);
   configuration.AddAssembly("com.Data");
   return configuration;
}

If you want to select configuration files based on the URL I would just identify the call stack that leads to this function and pass in either an enum value or the config file's name directly.

Spencer Ruport