Ejemplo n.º 1
0
        public void RunRegisteredInstancesWithContainerTest()
        {
            Console.WriteLine("Creating new unity container...");
            IUnityContainer container = new UnityContainer();

            Console.WriteLine("Registering fun stuff...");
            FunContainers.RegisterFunStuffForRegisterTest(container);

            Console.WriteLine("Resolving fun stuff...");
            IClown clown = container.Resolve <IClown>();

            clown.ClownName = "Bubbles";

            Console.WriteLine($"Clowns name is: {clown.ClownName}");

            IElephant elephant = container.Resolve <IElephant>();

            elephant.ElephantName = "Barbar";

            Console.WriteLine($"The elephants name is: {elephant.ElephantName}");

            IToilet toilet = container.Resolve <Toilet>();

            Console.WriteLine($"The toilet is hiding here: {toilet.ToiletLocation}");

            ICircus circus = container.Resolve <ICircus>(new ParameterOverride("clown", clown),
                                                         new ParameterOverride("elephant", elephant),
                                                         new ParameterOverride("location", "Some Place Imaginary"));

            Console.WriteLine("Executing circus methods...");
            Console.WriteLine(circus.GetLocation());
            circus.MakeElephantDoSomethingWithClown();
        }
Ejemplo n.º 2
0
        public void RunRegisteredInstancesWithNamedRegistrationTest()
        {
            Console.WriteLine("Creating new unity container...");
            IUnityContainer container = new UnityContainer();

            Console.WriteLine("Registering fun stuff...");
            FunContainers.RegisterFunStuffForNamedRegisterTest(container);

            IBear dancingBear = container.Resolve <IBear>("Dance");
            IBear singingBear = container.Resolve <IBear>("Sing");

            dancingBear.Perform();
            singingBear.Perform();
        }