public sealed class NHibernateSessionManager
{
#region Thread-safe, lazy Singleton
/// <summary>
/// This is a thread-safe, lazy singleton. See
http://www.yoda.arachsys.com/csharp/singleton.html /// for more details about its implementation.
/// 返回一个 NHibernateSessionManager
/// </summary>
public static NHibernateSessionManager Instance {
get {
return Nested.NHibernateSessionManager;
}
}
/// <summary>
/// Initializes the NHibernate session factory upon instantiation.
/// </summary>
private NHibernateSessionManager() {
InitSessionFactory();
}
/// <summary>
/// 确保线程安全、按需
/// Assists with ensuring thread-safe, lazy singleton
/// </summary>
private class Nested
{
static Nested() { }
/// <summary>
/// internal表示在当前程序集之外不可访问
/// </summary>
internal static readonly NHibernateSessionManager NHibernateSessionManager =
new NHibernateSessionManager();
}
#endregion
……
}
在codeproject.com上找的,比较有名的一个NHibernate&castle示例代码。