Exemple #1
0
        static void Main(string[] args)
        {
            Unity.IUnityContainer container = new Unity.UnityContainer();
            ContainerMagic.RegisterElements(container);

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

            Console.WriteLine($"Battery object: SerialNumber - {battery.SerialNumber()}");

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

            Console.WriteLine($"Tuner object: SerialNumber - {tuner.SerialNumber()}");

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

            Console.WriteLine($"Dial object: DialType - {dial.DialType()}");

            var radio = container.Resolve <IRadio>(new Unity.Resolution.ParameterOverride("radioBattery", battery),
                                                   new Unity.Resolution.ParameterOverride("radioTuner", tuner),
                                                   new Unity.Resolution.ParameterOverride("radioName", "RocketRadio"));

            radio.Start();

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

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

            Console.ReadLine();
        }
Exemple #2
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)"));
        }