在我们工作的数据访问层中,我们有这个标准实现,其中类是通过一个看起来像这样的单例公共属性访问的:
public static CustomerController Instance
{
get
{
lock(singletonLock)
{
if( _instance == null )
{
_instance = new CustomerController();
}
return _instance;
}
}
}
现在,我知道代码在做什么,但我想知道为什么你会在每次使用它时只创建一个类的实例?