Example #1
0
        public void TestResolveWithName()
        {
            IUnityContainer uc = new UnityContainer();

            UnityTestClass obj = uc.Resolve <UnityTestClass>("Hello");

            Assert.IsNotNull(obj);
        }
Example #2
0
        public void Test_TaskID_16777()
        {
            UnityContainer uc = new UnityContainer();

            uc.RemoveAllExtensions();
            uc.AddExtension(new MyExtension());
            uc.RegisterType <UnityTestClass>(new ContainerControlledLifetimeManager());

            UnityTestClass mytestparent = uc.Resolve <UnityTestClass>();
        }
Example #3
0
        public void UseExternallyControlledLifetimeResolve()
        {
            IUnityContainer parentuc = new UnityContainer();

            parentuc.RegisterType <UnityTestClass>(new ExternallyControlledLifetimeManager());

            UnityTestClass parentinstance = parentuc.Resolve <UnityTestClass>();

            parentinstance.Name = "Hello World Ob1";

            UnityTestClass parentinstance1 = parentuc.Resolve <UnityTestClass>();

            Assert.AreSame(parentinstance.Name, parentinstance1.Name);
        }
Example #4
0
        public void RegisterWithParentAndChild()
        {
            //create unity container
            IUnityContainer parentuc = new UnityContainer();

            //register type UnityTestClass
            parentuc.RegisterType <UnityTestClass>(new ContainerControlledLifetimeManager());

            UnityTestClass mytestparent = parentuc.Resolve <UnityTestClass>();

            mytestparent.Name = "Hello World";
            IUnityContainer childuc = parentuc.CreateChildContainer();

            childuc.RegisterType <UnityTestClass>(new ContainerControlledLifetimeManager());

            UnityTestClass mytestchild = childuc.Resolve <UnityTestClass>();

            Assert.AreNotSame(mytestparent.Name, mytestchild.Name);
        }
Example #5
0
        public void UseContainerControlledLifetime()
        {
            UnityTestClass obj1 = new UnityTestClass();

            obj1.Name = "InstanceObj";

            IUnityContainer parentuc = new UnityContainer();

            parentuc.RegisterType <UnityTestClass>(new ContainerControlledLifetimeManager());

            UnityTestClass parentinstance = parentuc.Resolve <UnityTestClass>();

            parentinstance.Name = "Hello World Ob1";
            parentinstance      = null;
            GC.Collect();

            UnityTestClass parentinstance1 = parentuc.Resolve <UnityTestClass>();

            Assert.AreSame("Hello World Ob1", parentinstance1.Name);
        }
Example #6
0
        public void UseContainerControlledLifetime()
        {
            UnityTestClass obj1 = new UnityTestClass();

            obj1.Name = "InstanceObj";

            UnityContainer parentuc = new UnityContainer();
            parentuc.RegisterType<UnityTestClass>(new ContainerControlledLifetimeManager());

            UnityTestClass parentinstance = parentuc.Resolve<UnityTestClass>();
            parentinstance.Name = "Hello World Ob1";
            parentinstance = null;
            GC.Collect();

            UnityTestClass parentinstance1 = parentuc.Resolve<UnityTestClass>();

            Assert.AreSame("Hello World Ob1", parentinstance1.Name);
        }