Ejemplo n.º 1
0
        static void Main(string[] args)
        {
            IUnityContainer container = new UnityContainer();

            ContainerMagic.RegisterElements(container);

            IBattery battery = container.Resolve <IBattery>();

            Console.WriteLine(battery.SerialNumber());

            Dial dial = container.Resolve <Dial>();

            Console.WriteLine(dial.DialType());

            ITuner tuner = container.Resolve <ITuner>();
            IRadio radio = container.Resolve <IRadio>(new ParameterOverride("radioBattery2", battery),
                                                      new ParameterOverride("radioTuner2", tuner),
                                                      new ParameterOverride("radioName", "BrokenRadio"));

            radio.Start();

            ISpeaker cheapSpeaker  = container.Resolve <ISpeaker>("Cheap");
            ISpeaker priceySpeaker = container.Resolve <ISpeaker>("Expensive");

            cheapSpeaker.Start();
            priceySpeaker.Start();



            // create a dummy extension for string
            String a = "Je suis une vrai string";

            Console.WriteLine(a + ", et en appelant MySuperExtentionMethod, ça retourne : " + a.MySuperExtentionMethod());

            // string format with property, of instance variable
            LogItem r = new LogItem()
            {
                ItemCount = 455
            };

            Console.WriteLine(String.Format($"Write cache dump {r} ({r.ItemCount} items affected)"));
        }
Ejemplo n.º 2
0
        static void Main(string[] args)
        {
            IUnityContainer container = new UnityContainer();

            Container.RegisterElements(container);

            IAdapter adapter = container.Resolve <IAdapter>();

            Console.WriteLine(adapter.Voltage());

            TVStand tvStand = container.Resolve <TVStand>();

            Console.WriteLine(tvStand.MaxInchesOfTVOnStand());

            IRemote     remote     = container.Resolve <IRemote>();
            ITelevision television = container.Resolve <ITelevision>
                                         (new ParameterOverride("adapter", adapter),
                                         new ParameterOverride("remote", remote),
                                         new ParameterOverride("manufacturer", "Visio"),
                                         new ParameterOverride("modelNumber", "321asdf"));


            television.TurnOn();

            Console.ReadLine();

            ISpeaker cheapSpeaker  = container.Resolve <ISpeaker>("Cheap");
            ISpeaker priceySpeaker = container.Resolve <ISpeaker>("Expensive");

            cheapSpeaker.Start();
            priceySpeaker.Start();

            Console.ReadLine();

            IBox casing = container.Resolve <IBox>();

            Console.WriteLine(casing.TypeOfMaterial());

            Console.ReadLine();
        }
Ejemplo n.º 3
0
        static void Main(string[] args)
        {
            IUnityContainer container = new UnityContainer();

            ContainerMagic.RegisterElements(container);

            IBattery battery = container.Resolve <IBattery>();

            Console.WriteLine(battery.SerialNumber());

            Dial dial = container.Resolve <Dial>(new ParameterOverride("typeOfDial", "linear"));

            Console.WriteLine(dial.DialType());

            ITuner tuner = container.Resolve <ITuner>();

            Console.WriteLine(tuner.SerialNumber());
            IRadio radio = container.Resolve <IRadio>(new ParameterOverride("radioBattery", battery),
                                                      new ParameterOverride("radioTuner", tuner),
                                                      new ParameterOverride("radioName", "BrokenRadio"));

            radio.Start();

            ISpeaker cheapSpeaker  = container.Resolve <ISpeaker>("Cheap");
            ISpeaker priceySpeaker = container.Resolve <ISpeaker>("Expensive");

            cheapSpeaker.Start();
            priceySpeaker.Start();

            ICasing casing = container.Resolve <ICasing>();

            Console.WriteLine(casing.TypeOfMaterial());

            Console.WriteLine("Press any key to continue...");
            Console.ReadLine();
        }