Static Constructor & Singleton class

后端 未结 2 1230
执念已碎
执念已碎 2021-02-05 06:23

I have an object cache which implements the Singleton design pattern. My approach to singleton was always to lazy load the static instance when the property is first accessed. <

相关标签:
2条回答
  • 2021-02-05 07:12

    Jon Skeet has a nice article on singletons discussing this issue.

    0 讨论(0)
  • 2021-02-05 07:25

    Rather than rolling your own threadsafe lazy initializer and possibly getting it wrong, I recommend reading the msdn on Lazy<T>.

    https://docs.microsoft.com/en-us/dotnet/framework/performance/lazy-initialization#thread-safe-initialization

    0 讨论(0)
提交回复
热议问题