Creates a singleton class with System Lazy<T>




    C# recipes

    The preceding code declares a class named MyClass and defines a private static readonly instance of a type called Lazy<I${2}> . This instance is initialized with a new expression that creates a new instance of the type I${2} .

    Shortcut: singletonl

    public sealed class MyClass : IMyObject
      private static readonly Lazy<I${2}> _instance = new Lazy<I${2}>(() => new ${1}());
      public static I${2} Instance { get { return _instance.Value; } }
      private ${1}()
    Codiga Logo
    Codiga Hub
    • Rulesets
    • Explore
    • Cookbooks
    • Playground
    soc-2 icon

    We are SOC-2 Compliance Certified

    G2 high performer medal

    Codiga – All rights reserved 2022.