Singletons are boring, hence factor out the concern
dotnetkicks has an astonishing amount of entries related to “The Singleton”®…
Regardless of whether Singletons are considered harmful or not, I could not resist but provide you with my own take on factoring out the need to get a Singleton which doesn’t feel like a Singleton at all. We can single-ton out any classes that provide a default constructor. Due to the reflection spice you can provide a private one as well. Takes somewhat longer, but you’re only doing it once, don’t you ;) ?
The implicit operator makes it possible to do this:
Doesn’t it look funny? I find it quite likeable and you definitely don’t pollute the class in question with some singleton boilerplate. I would like to say “Go forth and multiply” but it seems wholly inappropriate for the issue at hand…