Bring back the Singleton<T>? #4108
-
About the singleton, following thread had discussed a lot but recently, i found the following pattern
The Pattern is copied from the book "CLR Via C# 4th Edition by Jeffrey Richter Chapter 30 The Famous Double-Check Locking Technique" i mean it's been over 10 years, we still keep writing wrong codes, again and again. so in a word, should you guys bring back the Singleton? BTW, the book also state, FCL class guarantee the static method is thread safe(according to the book) |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 2 replies
-
@OneFingerCodingWarrior as the issue on why we removed Singleton states to achieve this with C#, you just need to do this: public static MyClass Instance { get; } = new(); That's it. That's why we removed the class as it's trivial to do now. We updated our code in the Toolkit to do this. I believe we had a deprecation message mentioning this as well. FYI @Sergio0694 (Also, please don't paste an excerpt of copyrighted material in full, I've deleted your 2nd comment.) |
Beta Was this translation helpful? Give feedback.
-
Got it! |
Beta Was this translation helpful? Give feedback.
@OneFingerCodingWarrior as the issue on why we removed Singleton states to achieve this with C#, you just need to do this:
That's it. That's why we removed the class as it's trivial to do now. We updated our code in the Toolkit to do this. I believe we had a deprecation message mentioning this as well.
FYI @Sergio0694
(Also, please don't paste an excerpt of copyrighted material in full, I've deleted your 2nd comment.)