public class MySingletonClass
{
public MySingletonClass()
{
_mySingletonObj = Instance();
}
public static MySingletonClass Instance()
{
if (_mySingletonObj == null
我正在嘗試創建一個單身人士服務,用於處理傳入的請求到HttpHandler。目前該服務正在根據每個請求進行實例化。我做對包含服務的實例的靜態類的調用,如一個單如下實施:在HttpHandler的使用調用如下 public static class ServerApplication {
static Service instance = null;
static readonly objec
比方說,我有一個單例類是這樣的: class Settings
include Singleton
def timeout
# lazy-load timeout from config file, or whatever
end
end
現在,如果我想知道是幹什麼用的超時我需要寫類似: Settings.instance.timeout
但我寧