We succesfully map entities from multiple assemblies by using NHibernate.Cfg.Configuration.AddAssembly() multiple times. A code snippet is below. As you can see, we inspect all assemblies in the current domain and any assembly that has our own custom attribute called "HibernatePersistenceAssembly" on it gets added. We created this attribute simply so that this loop would know which assemblies have NHibernate entities in them, but you could use whatever scheme you want to decide which assemblies to add including simply hardwiring them if you wanted to.
In AssemblyInfo.cs for each Assembly that has NHibernate entities in it:
[assembly: HibernatePersistenceAssembly()]
And then in our Hibernate Utilities class:
public NHibernate.Cfg.Configuration ReloadConfiguration()
{
configuration = new NHibernate.Cfg.Configuration();
configuration.Configure();
ConfigureConnectionString();
ConfigureAssemblies();
return configuration;
}
private void ConfigureAssemblies()
{
foreach (Assembly assembly in AppDomain.CurrentDomain.GetAssemblies())
{
foreach (object attribute in assembly.GetCustomAttributes(true))
{
if (attribute is HibernatePersistenceAssembly)
configuration.AddAssembly(assembly);
}
}
}