static void Main(string[] args)
        {
            var db   = SingletonDatabase.Instance;
            var city = "Tokyo";

            WriteLine($"{city} has population {db.GetPopulation(city)}");

            var cb = new ContainerBuilder();

            cb.RegisterType <OrdinaryDatabase>().As <IDatabase>().SingleInstance();
            var container = cb.Build();

            var odb1 = container.Resolve <IDatabase>();
            var odb2 = container.Resolve <IDatabase>();

            WriteLine($"Does OrdinaryDatabase return the same instance? : {odb1 != null && odb1.Equals(odb2)}");

            // monostate
            var ceo1 = new CEO()
            {
                Name = "Adam Smith",
                Age  = 55,
            };

            var ceo2 = new CEO();

            WriteLine(ceo2);
        }
Beispiel #2
0
        public static void Example()
        {
            var ceo = new CEO();

            ceo.Name = "Adam Smith";
            ceo.Age  = 57;

            var ceo2 = new CEO();

            Console.WriteLine($"First instance of CEO class: {ceo}");
            Console.WriteLine($"Second instance of CEO class:{ceo2}");
        }
Beispiel #3
0
        static void Main(string[] args)
        {
            var db = SingletonDatabase.Instance;

            System.Console.WriteLine(db.GetPopulation("Tokyo"));

            var ceo = new CEO();

            ceo.Name = "John Doe";
            ceo.Age  = 55;

            var ceo2 = new CEO();

            System.Console.WriteLine(ceo2.Name + " " + ceo2.Age); // John Doe 55
        }