singleton

    1熱度

    1回答

    在我們的系統中,我們經常收到一次用戶請求的數量。所以我們正在創建原型bean並開始處理請求。 在這些原型bean中,我們當然會使用其他一些bean。 所以我的問題:是明智的,可以在原型bean中使用singleton-beans?如果是的話,正確使用的條件是什麼? 我會認爲,如果我只讓一個singleton服務被大量的prototype bean使用,它是有效的。 但是當幾個bean在同一時間要求

    0熱度

    2回答

    void build(){ while(true){ Builder builder = new Builder(); ... } } class Builder{ private final Store store = null; public Builder(){ store = Store.getInstance(

    2熱度

    1回答

    我發現無數的例子在斯威夫特3.我試圖用這個方法使用Singleton模式: class Records: RailsData { static let shared = Records() private init() {} ... } 當我這樣做,我得到的編譯器錯誤: Overriding declaration requires an 'override'

    0熱度

    1回答

    試圖重構我的代碼,以避免必須在整個地方引用共享實例,而我想通過自定義初始化程序注入它們。我對Swift初始化的理解有限讓我無法這樣做。 這裏是我的ViewController,減去的方法和樣板: class LoginVC: UIViewController { let dataManager: DataManager let restManager: RestManager

    0熱度

    1回答

    我正在編寫連接到數據庫的應用程序。我需要能夠使用來自許多類的DataBase連接。 class Database { auto MyConnection = new Connection("..."); // create connection void calc() { MyConnection.query("..."); // use it

    0熱度

    2回答

    Laravel 5.4中不再支持共享函數。建議使用singleton()。所以我嘗試了幾件事情。 這是代碼我想與單來代替() $this->bind('Configuration', $this->share(function() use ($config) { return new Configuration($config); }), true ); 任何

    2熱度

    3回答

    我是新來設計C#模式。任何人都可以給我一些關於Singleton類的實現的說明。我剛剛實現了一個教程,但我無法理解單例類的使用,這個「單例表示我們只能創建一個類的一個實例」。那麼爲什麼我們不使用兩個不同類的實例訪問單例類中寫入的屬性。 請看我的代碼,並給我說明我犯的錯誤。 static void Main(string[] args) { Singleton instance = S

    2熱度

    2回答

    大家好我想要在Singleton類中的一個字符串屬性上實現KVO。當我嘗試添加觀察者時,我正遇到一些錯誤,並希望有人能告訴我我做錯了什麼。 下面顯示了我的單身人士課程。 class User: NSObject { static let currentUser = User() private override init() {} var pictureStrin

    1熱度

    2回答

    在團結,因爲我知道我可以使用下面的2個選項來註冊一個單例: IConfiguration globalConfig = new Configuration(); container.RegisterInstance<IConfiguration>(globalConfig); container.RegisterType<IConfiguration, Configur

    0熱度

    1回答

    我有一個Sync類,它基本上在後臺將數據同步到服務器。 使用Sync類對象時,使得類似Sync類對象的同步請求所在的View Controller可能會在同步實際完成之前解除分配。 我在這裏面臨的問題是Sync類對象也被釋放,因此同步請求永遠不會完成。 我認爲Sync類作爲一個單例,但這將更多的濫用Singleton模式。 我該如何繼續?