Here's a simple solution that Ayende showed to speed up the NHibernate startup time. The following will work great for production systems. You would need something a little more complex for development since you would need to re-save the cfg file anytime you change your mappings.
if (!File.Exists("nh.cfg"))
{
// Build your nh configuration
Configuration configuration = new Configuration()
.Configure("NHibernate.config");
// write the config out to a file (the configuration is expensive to create)
new BinaryFormatter().Serialize(File.Create("nh.cfg"), configuration);
}
var configuration = (Configuration)new BinaryFormatter().Deserialize(
File.Open("nh.cfg", FileMode.Open)
);
ISessionFactory factory = configuration.BuildSessionFactory();
0 comments:
Post a Comment