示例#1
0
        public void TypeBasedOverrideConstructorWithNoTypeMatch()
        {
            IForTypeToInject  defaultValue      = new TypeToInject1ForTypeOverride(111);
            IForTypeToInject  overrideValue     = new TypeToInject2ForTypeOverride(222);
            ParameterOverride overrideParam     = new ParameterOverride("injectedObject", overrideValue);
            TypeBasedOverride overrideDecorator = new TypeBasedOverride(typeof(int), overrideParam);

            IUnityContainer container = new UnityContainer();

            container.RegisterType <IForToUndergoeInject, TypeToUndergoeTypeBasedInject1>(new InjectionConstructor(defaultValue));
            var result = container.Resolve <IForToUndergoeInject>(overrideDecorator);

            Assert.AreEqual <int>(111, result.IForTypeToInject.Value);
        }
示例#2
0
        public void TypeBasedOverrideWithResolveAll()
        {
            IForTypeToInject  defaultValue      = new TypeToInject1ForTypeOverride(111);
            IForTypeToInject  overrideValue     = new TypeToInject1ForTypeOverride(222);
            ParameterOverride overrideParam     = new ParameterOverride("injectedObject", overrideValue);
            TypeBasedOverride overrideDecorator = new TypeBasedOverride(typeof(TypeToUndergoeTypeBasedInject1), overrideParam);

            IUnityContainer container = new UnityContainer();

            container.RegisterType <IForToUndergoeInject, TypeToUndergoeTypeBasedInject1>(new InjectionConstructor(defaultValue)).RegisterType <IForToUndergoeInject, TypeToUndergoeTypeBasedInject1>("Named", new InjectionConstructor(defaultValue));
            var resultList = container.ResolveAll <IForToUndergoeInject>(overrideDecorator);

            foreach (var result in resultList)
            {
                Assert.AreEqual <int>(222, result.IForTypeToInject.Value);
            }
        }
示例#3
0
        public void TypeBasedOverrideConstructorWithNoTypeMatch()
        {
            IForTypeToInject defaultValue = new TypeToInject1ForTypeOverride(111);
            IForTypeToInject overrideValue = new TypeToInject2ForTypeOverride(222);
            ParameterOverride overrideParam = new ParameterOverride("injectedObject", overrideValue);
            TypeBasedOverride overrideDecorator = new TypeBasedOverride(typeof(int), overrideParam);

            IUnityContainer container = new UnityContainer();

            container.RegisterType<IForToUndergoeInject, TypeToUndergoeTypeBasedInject1>(new InjectionConstructor(defaultValue));
            var result = container.Resolve<IForToUndergoeInject>(overrideDecorator);

            Assert.AreEqual<int>(111, result.IForTypeToInject.Value);
        }
示例#4
0
        public void TypeBasedOverrideWithResolveAll()
        {
            IForTypeToInject defaultValue = new TypeToInject1ForTypeOverride(111);
            IForTypeToInject overrideValue = new TypeToInject1ForTypeOverride(222);
            ParameterOverride overrideParam = new ParameterOverride("injectedObject", overrideValue);
            TypeBasedOverride overrideDecorator = new TypeBasedOverride(typeof(TypeToUndergoeTypeBasedInject1), overrideParam);

            IUnityContainer container = new UnityContainer();

            container.RegisterType<IForToUndergoeInject, TypeToUndergoeTypeBasedInject1>(new InjectionConstructor(defaultValue)).RegisterType<IForToUndergoeInject, TypeToUndergoeTypeBasedInject1>("Named", new InjectionConstructor(defaultValue));
            var resultList = container.ResolveAll<IForToUndergoeInject>(overrideDecorator);

            foreach (var result in resultList)
            {
                Assert.AreEqual<int>(222, result.IForTypeToInject.Value);
            }
        }