Disposable singleton in C#

前端 未结 8 1838
Happy的楠姐
Happy的楠姐 2020-12-05 08:14

I have a singleton that uses the \"static readonly T Instance = new T();\" pattern. However, I ran into a case where T is disposable, and actually needs to be disposed for u

8条回答
  •  南笙
    南笙 (楼主)
    2020-12-05 08:50

    Singletons should not be Disposable. Period. If someone calls Dispose prematurely, your application is screwed until it restarts.

提交回复
热议问题