Beispiel #1
0
        public void DuplicateRegInParentAndChild()
        {
            IA a = new A();
            IB b = new B(a);

            var parent = new QuickInjectContainer();

            parent.RegisterInstance(a).RegisterInstance(b);

            IQuickInjectContainer child = parent.CreateChildContainer();

            var childA  = child.Resolve <IA>();
            var parentA = parent.Resolve <IA>();

            var childB  = child.Resolve <IB>();
            var parentB = parent.Resolve <IB>();

            Assert.IsTrue(childA == parentA);
            Assert.IsTrue(childB == parentB);
        }
Beispiel #2
0
        public void ChildRegistrationIsChosenWhenResolvedFromChild()
        {
            IA aParent = new A();
            IA aChild  = new A();

            var parent = new QuickInjectContainer();

            parent.RegisterInstance(aParent);

            IQuickInjectContainer child = parent.CreateChildContainer();

            child.RegisterInstance(aChild);


            Assert.IsTrue(aChild == child.Resolve <IA>());
            Assert.IsTrue(aParent == parent.Resolve <IA>());
        }
Beispiel #3
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);
        }
 public static T Resolve <T>(this IQuickInjectContainer container, object resolutionContext)
 {
     return((T)container.Resolve(typeof(T), resolutionContext));
 }
 public static T Resolve <T>(this IQuickInjectContainer container)
 {
     return((T)container.Resolve(typeof(T)));
 }