Starting with some code:
sessionFactory = Fluently.Configure(cfg)
.Mappings(m =>
{
List<Assembly> allAssemblies = new List<Assembly>();
string path = Assembly.GetExecutingAssembly().Location;
foreach (string dll in Directory.GetFiles(path, "*.dll"))
{
m.FluentMappings.AddFromAssembly(Assembly.LoadFile(dll));
}
})
.BuildSessionFactory();
I'm very new to both nhibernate and fluent nhibernate. The bit of code above looks like it should work, but to me it looks really ugly. Is there a neater way?
One problem I have is that the code that calls the above code is in a core assembly and is unable to make reference to some of the assemblies that need mapping as their assemblies reference the core assembly. So I can't just use a few calls to AddFromAssemblyOf<T>
.
Is there a cleaner way to do this?