65.9K
CodeProject is changing. Read more.
Home

common Singleton Pattern implementation using Generic

emptyStarIconemptyStarIconemptyStarIconemptyStarIconemptyStarIcon

0/5 (0 vote)

Oct 5, 2011

CPOL
viewsIcon

11011

All classes are naturally Lazy loaded.So a better implementation will be:public class Singletonwhere T: new(){ public static readonly T Instance = new T();}You will notice that before calling the singleton class, the object will not be loaded.Surely there are...

All classes are naturally Lazy loaded. So a better implementation will be:
public class Singleton<T>
where T: new()
{
  public static readonly T Instance = new T();
}
You will notice that before calling the singleton class, the object will not be loaded. Surely there are differences (as you may want to get the type without instantiating its inner items), but for a general purpose, it works.