public void CanOverrideConstructorDependencyInConfiguration()
        {
            var overriddenTypeToInject = new TypeToInject3(-9999);

            IUnityContainer container = GetContainer(ContainerName);

            var injectedObjectWithDefault = container.Resolve <SubjectType1ToInject>("TestConstructorOverrideDefaultInConfiguration");
            var overridenInjectedObject   = container.Resolve <SubjectType1ToInject>("TestConstructorOverrideDefaultInConfiguration", new ParameterOverride("injectedObject", overriddenTypeToInject));

            Assert.IsInstanceOfType(overridenInjectedObject.InjectedObject, typeof(TypeToInject3));
        }
        public void CanOverrideMultipleTimes()
        {
            IInterfaceForTypesToInject defaultParameter = new TypeToInject1(9999);

            IInterfaceForTypesToInject overrideInjectionParameter1 = new TypeToInject2(9999);
            IInterfaceForTypesToInject overrideInjectionParameter2 = new TypeToInject3(8888);
            var container = new UnityContainer()
                .RegisterType<SubjectType1ToInject>(new InjectionConstructor(defaultParameter));

            var result1 =
                container.Resolve<SubjectType1ToInject>(new ParameterOverride("injectedObject", overrideInjectionParameter1));

            var result2 =
                container.Resolve<SubjectType1ToInject>(new ParameterOverride("injectedObject", overrideInjectionParameter2));
            var result3 =
                container.Resolve<SubjectType1ToInject>();

            Assert.IsInstanceOfType(result1.InjectedObject, typeof(TypeToInject2));
            Assert.IsInstanceOfType(result2.InjectedObject, typeof(TypeToInject3));
        }
        public void CanOverrideMultipleTimes()
        {
            IInterfaceForTypesToInject defaultParameter = new TypeToInject1(9999);

            IInterfaceForTypesToInject overrideInjectionParameter1 = new TypeToInject2(9999);
            IInterfaceForTypesToInject overrideInjectionParameter2 = new TypeToInject3(8888);
            var container = new UnityContainer()
                            .RegisterType <SubjectType1ToInject>(new InjectionConstructor(defaultParameter));

            var result1 =
                container.Resolve <SubjectType1ToInject>(new ParameterOverride("injectedObject", overrideInjectionParameter1));

            var result2 =
                container.Resolve <SubjectType1ToInject>(new ParameterOverride("injectedObject", overrideInjectionParameter2));
            var result3 =
                container.Resolve <SubjectType1ToInject>();

            Assert.IsInstanceOfType(result1.InjectedObject, typeof(TypeToInject2));
            Assert.IsInstanceOfType(result2.InjectedObject, typeof(TypeToInject3));
        }
        public void WhenInjectingConstructorWithContainerControllerLifeTime()
        {
            IInterfaceForTypesToInject defaultParameter            = new TypeToInject1(9999);
            IInterfaceForTypesToInject overrideInjectionParameter  = new TypeToInject2(8888);
            IInterfaceForTypesToInject overrideInjectionParameter1 = new TypeToInject3(7777);

            var container = new UnityContainer()
                            .RegisterType <SubjectType1ToInject>(new ContainerControlledLifetimeManager(), new InjectionConstructor(defaultParameter));

            var result1 =
                container.Resolve <SubjectType1ToInject>(new ParameterOverride("injectedObject", overrideInjectionParameter));
            var result2 =
                container.Resolve <SubjectType1ToInject>(new ParameterOverride("injectedObject", overrideInjectionParameter1));
            var result3 =
                container.Resolve <SubjectType1ToInject>();

            Assert.IsInstanceOfType(result1.InjectedObject, typeof(TypeToInject2));
            Assert.IsInstanceOfType(result2.InjectedObject, typeof(TypeToInject2));
            Assert.IsInstanceOfType(result2.InjectedObject, typeof(TypeToInject2));
        }
        public void OverrideReturnedOnlyOnceWhenDefaultInConfiguration()
        {
            var overriddenTypeToInject = new TypeToInject3(-9999);

            IUnityContainer container = GetContainer(ContainerName);

            var overridenInjectedObject = container.Resolve<SubjectType1ToInject>("TestConstructorOverrideDefaultInConfiguration", new ParameterOverride("injectedObject", overriddenTypeToInject));
            var injectedObjectWithDefault = container.Resolve<SubjectType1ToInject>("TestConstructorOverrideDefaultInConfiguration");
            
            Assert.IsInstanceOfType(overridenInjectedObject.InjectedObject, typeof(TypeToInject3));
            Assert.IsInstanceOfType(injectedObjectWithDefault.InjectedObject, typeof(TypeToInject1));
        }
        public void WhenInjectingConstructorWithContainerControllerLifeTime()
        {
            IInterfaceForTypesToInject defaultParameter = new TypeToInject1(9999);
            IInterfaceForTypesToInject overrideInjectionParameter = new TypeToInject2(8888);
            IInterfaceForTypesToInject overrideInjectionParameter1 = new TypeToInject3(7777);
         
            var container = new UnityContainer()
                .RegisterType<SubjectType1ToInject>(new ContainerControlledLifetimeManager(), new InjectionConstructor(defaultParameter));

            var result1 =
                container.Resolve<SubjectType1ToInject>(new ParameterOverride("injectedObject", overrideInjectionParameter));
            var result2 =
                container.Resolve<SubjectType1ToInject>(new ParameterOverride("injectedObject", overrideInjectionParameter1));
            var result3 =
                container.Resolve<SubjectType1ToInject>();

            Assert.IsInstanceOfType(result1.InjectedObject, typeof(TypeToInject2));
            Assert.IsInstanceOfType(result2.InjectedObject, typeof(TypeToInject2));
            Assert.IsInstanceOfType(result2.InjectedObject, typeof(TypeToInject2));
        }