Delay creation of instance of XmlSerializer (loading xml assembly) until its needed.
Description
The solution to wasn't the most wise one IMHO. Now there's a static field in configuration.cs which initializes a XmlSerializer even if you don't need it (ie. when mapping by code and you have no hbm.xml files). Starting the XML assembly takes up nearly a second on my fairly new PC, so a better initialization would be helpful.
The current line of code is:
private static XmlSerializer _mappingDocumentSerializer = new XmlSerializer(typeof (HbmMapping));
The solution to wasn't the most wise one IMHO. Now there's a static field in configuration.cs which initializes a XmlSerializer even if you don't need it (ie. when mapping by code and you have no hbm.xml files). Starting the XML assembly takes up nearly a second on my fairly new PC, so a better initialization would be helpful.
The current line of code is:
private static XmlSerializer _mappingDocumentSerializer = new XmlSerializer(typeof (HbmMapping));
my suggestion is to rewrite this code to:
private static XmlSerializer _mappingDocumentSerializer = null;
private XmlSerializer mappingDocumentSerializer
{
get
{
if (_mappingDocumentSerializer == null)
_mappingDocumentSerializer = new XmlSerializer(typeof (HbmMapping));
return _mappingDocumentSerializer;
}
}
This way the XmlSerializer will only be created once as well, but only when it's really needed. More info on unnecessary initialization can be found in this article: http://msdn.microsoft.com/en-us/magazine/cc163655.aspx#S3