Ejemplo n.º 1
0
        public void UseExternallyControlledLifetimeResolve()
        {
            IQuickInjectContainer parentuc = new QuickInjectContainer();

            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);
        }
Ejemplo n.º 2
0
        public void RegisterWithParentAndChild()
        {
            //create unity container
            var parentuc = new QuickInjectContainer();

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

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

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

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

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

            Assert.AreNotSame(mytestparent.Name, mytestchild.Name);
        }
Ejemplo n.º 3
0
        public void UseContainerControlledLifetime()
        {
            UnityTestClass obj1 = new UnityTestClass();

            obj1.Name = "InstanceObj";

            var parentuc = new QuickInjectContainer();

            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);
        }
Ejemplo n.º 4
0
        public void UseContainerControlledLifetime()
        {
            UnityTestClass obj1 = new UnityTestClass();

            obj1.Name = "InstanceObj";

            var parentuc = new QuickInjectContainer();
            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);
        }