Reducing application startup time
The process of configuring NHibernate is fairly intensive and takes time. NHibernate has to load, parse, and compile all our mappings and reflect the model. In this recipe, we'll show you how to reduce the start up time of your NHibernate application.
Getting ready
Complete the Configuring NHibernate with App.config
recipe discussed in the Chapter 1, The Configuration and Schema.
How to do it…
Add a reference to
System.Configuration.dll
.Add a new class named
ConfigurationBuilder
:using System; using System.Configuration; using System.IO; using System.Reflection; using System.Runtime.Serialization.Formatters.Binary; using Configuration = NHibernate.Cfg.Configuration; namespace ConfigByAppConfig { public class ConfigurationBuilder { private const string SERIALIZED_CFG = "configuration.bin"; } }
Add a method named
Build
with the following code:public Configuration Build() { Configuration cfg = LoadConfigurationFromFile(); if...