Пример #1
0
        public void MoreChildContainers1()
        {
            UnityContainer parent = new UnityContainer();

            parent.RegisterType <ITemporary, Temp>("First");
            parent.RegisterType <ITemporary, Temp>("First");
            UnityContainer child1 = (UnityContainer)parent.CreateChildContainer();

            child1.RegisterType <ITemporary, Temp>("First");
            child1.RegisterType <ITemporary, Temp>("First");
            UnityContainer child2 = (UnityContainer)child1.CreateChildContainer();

            child2.RegisterType <ITemporary, Temp>("First");
            child2.RegisterType <ITemporary, Temp>("First");
            UnityContainer child3 = (UnityContainer)child2.CreateChildContainer();

            child3.RegisterType <ITemporary, Temp>("First");
            child3.RegisterType <ITemporary, Temp>("First");
            IUnityContainer child4 = child3.CreateChildContainer();

            child4.RegisterType <ITemporary, Temp>("First");
            ITemporary first = child4.Resolve <ITemporary>("First");

            child4.RegisterType <ITemporary, Temp>("First", new ContainerControlledLifetimeManager());
            List <ITemporary> count = new List <ITemporary>(child4.ResolveAll <ITemporary>());

            Assert.AreEqual(1, count.Count);
        }
Пример #2
0
        public void NamesRegisteredInParentAppearInChild()
        {
            UnityContainer parent = new UnityContainer();

            parent.RegisterType <ITemporary, SpecialTemp>("test");
            IUnityContainer child = parent.CreateChildContainer();

            ITemporary temp = child.Resolve <ITemporary>("test");

            Assert.IsInstanceOfType(temp, typeof(SpecialTemp));
        }
Пример #3
0
        public void CreateChildUsingParentsConfiguration()
        {
            UnityContainer parent = new UnityContainer();

            parent.RegisterType <ITemporary, Temporary>();
            IUnityContainer child = parent.CreateChildContainer();

            ITemporary temp = child.Resolve <ITemporary>();

            Assert.IsNotNull(temp);
            Assert.IsInstanceOfType(temp, typeof(Temporary));
        }
        public void RegisterNamedTypesandGetThroughConfig()
        {
            IUnityContainer uc = new UnityContainer();

            uc.RegisterType <ITemporary, Temp>();
            uc.RegisterType <ITemporary, Temporary>("Temporary");

            //TODO: what does this prove?
            string     str2 = ConfigurationManager.AppSettings["TypeName2"].ToString();
            ITemporary temp = uc.Resolve <ITemporary>(str2);

            Assert.IsInstanceOfType(temp, typeof(Temporary));
        }
Пример #5
0
        public void ChildConfigurationOverridesParentConfiguration()
        {
            UnityContainer parent = new UnityContainer();

            parent.RegisterType <ITemporary, Temporary>();

            IUnityContainer child = parent.CreateChildContainer()
                                    .RegisterType <ITemporary, SpecialTemp>();

            ITemporary parentTemp = parent.Resolve <ITemporary>();
            ITemporary childTemp  = child.Resolve <ITemporary>();

            Assert.IsInstanceOfType(parentTemp, typeof(Temporary));
            Assert.IsInstanceOfType(childTemp, typeof(SpecialTemp));
        }
        public void GetInterfaceUsingNonGenericMethods()
        {
            IUnityContainer uc = new UnityContainer()
                                 .RegisterType(typeof(ITemporary), typeof(Temp), "First")
                                 .RegisterType(typeof(ITemporary), typeof(Temporary));

            ITemporary temp      = uc.Resolve(typeof(ITemporary), "First") as ITemporary;
            ITemporary temporary = uc.Resolve(typeof(ITemporary)) as ITemporary;

            Assert.IsNotNull(temp);
            Assert.IsNotNull(temporary);

            Assert.IsInstanceOfType(temp, typeof(Temp));
            Assert.IsInstanceOfType(temporary, typeof(Temporary));
        }
Пример #7
0
 public TemporaryConsumer(ITemporary temporary)
 {
     Temporary = temporary;
 }