Hi,
I created a Singleton class in c#, with a public property that I want to initialize when the Singleton is first called.
This is the code I wrote :
public class BL
{
private ISessionFactory _sessionFactory;
public ISessionFactory SessionFactory
{
get { return _sessionFactory; }
set { _sessionFactory = value; }
}
private BL()
{
SessionFactory = Dal.SessionFactory.CreateSessionFactory();
}
private object thisLock = new object();
private BL _instance = null;
public BL Instance
{
get
{
lock (thisLock)
{
if (_instance == null)
{
_instance = new BL();
}
return _instance;
}
}
}
}
As far as I know, when I address the Instance BL object in the BL class for the first time, it should load the constructor and that should initialize the SessionFactory object.
But when I try : BL.Instance.SessionFactory.OpenSession(); I get a Null Reference Exception, and I see that SessionFactory is null...
why?