Development With A Dot

Blog on development in general, and specifically on .NET



My Friends

My Links

Permanent Posts

Portuguese Communities

Speeding Up NHibernate Startup Time

One technique I use and posted on the NHUsers mailing list consists in serializing a previously-configured Configuration to the filesystem and deserializing it on all subsequente starts of the application:

Configuration cfg = null;
IFormatter serializer = new BinaryFormatter();

//first time
cfg = new Configuration().Configure();

using (Stream stream = File.OpenWrite("Configuration.serialized"))
	serializer.Serialize(stream, configuration);

//other times
using (Stream stream = File.OpenRead("Configuration.serialized"))
	cfg = serializer.Deserialize(stream) as Configuration;

Check it out for yourselves.

Update: Fabio Maulo posted about this some time ago on NHForge. You can find his post here. Bookmark and Share


mxmissile said:

I wonder if this could be used with Fluent-Nhibernate? Going to test.

# March 31, 2010 1:27 PM

Ricardo Peres said:


Post updated, thanks. I probably learned about it there, can't remember.

# April 1, 2010 5:37 AM

vmr_lethal said:

may be better, we store the sessionFactory, I do this :)

# April 1, 2010 3:28 PM

David Kemp said:

This requires _everything_ to be Seralizable...hmm.

# April 6, 2010 12:27 PM

Ricardo Peres said:


Everything referred by the Configuration class IS serializable! Not the entities themselves, that is.

# April 6, 2010 1:21 PM

Ricardo Peres said:


It is the same, I think: just serialize the config object.


# December 8, 2010 1:50 AM