public void OverrideFromOther() { RootObjectDefinition rod = new RootObjectDefinition(typeof(TestObject), AutoWiringMode.Constructor); rod.IsSingleton = false; rod.InitMethodName = "Umberto Eco"; rod.DestroyMethodName = "Pedulismus"; rod.ConstructorArgumentValues = new ConstructorArgumentValues(); rod.ConstructorArgumentValues.AddGenericArgumentValue("Wulf", "Sternhammer"); rod.DependencyCheck = DependencyCheckingMode.Objects; rod.DependsOn = new string[] { "Jimmy", "Joyce" }; rod.IsAbstract = true; rod.IsLazyInit = true; rod.FactoryMethodName = "IfINeedYouIllJustUseYourSimpleName"; rod.FactoryObjectName = "PerspirationShop"; rod.ResourceDescription = "Ohhh"; rod.PropertyValues = new MutablePropertyValues(); rod.PropertyValues.Add("Age", 100); rod.EventHandlerValues = new EventValues(); InstanceEventHandlerValue handler = new InstanceEventHandlerValue(new TestObject(), "Ping"); handler.EventName = "Bing"; rod.EventHandlerValues.AddHandler(handler); ChildObjectDefinition cod = new ChildObjectDefinition("parent"); cod.ObjectTypeName = "ChildObjectTypeName"; cod.IsSingleton = true; cod.AutowireMode = AutoWiringMode.ByType; cod.InitMethodName = "InitChild"; cod.DestroyMethodName = "DestroyChild"; cod.ConstructorArgumentValues = new ConstructorArgumentValues(); cod.ConstructorArgumentValues.AddNamedArgumentValue("ctorarg", "ctorarg-value"); cod.DependencyCheck = DependencyCheckingMode.None; cod.DependsOn = new string[] { "Aleks", "Mark" }; cod.IsAbstract = false; cod.IsLazyInit = false; cod.FactoryMethodName = "ChildFactoryMethodName"; cod.FactoryObjectName = "ChildFactoryObjectName"; cod.ResourceDescription = "ChildResourceDescription"; cod.PropertyValues = new MutablePropertyValues(); cod.PropertyValues.Add("Prop1", "Val1"); cod.PropertyValues.Add("Age", 50); cod.EventHandlerValues = new EventValues(); handler = new InstanceEventHandlerValue(new TestObject(), "Pong"); handler.EventName = "Bong"; cod.EventHandlerValues.AddHandler(handler); rod.OverrideFrom(cod); // ... Assert.AreEqual("ChildObjectTypeName", rod.ObjectTypeName); Assert.AreEqual(AutoWiringMode.ByType, rod.AutowireMode); Assert.AreEqual(true, rod.IsSingleton); Assert.AreEqual("InitChild", rod.InitMethodName); Assert.AreEqual("DestroyChild", rod.DestroyMethodName); Assert.AreEqual(DependencyCheckingMode.None, rod.DependencyCheck); Assert.AreEqual(4, rod.DependsOn.Count); Assert.AreEqual(false, rod.IsAbstract); Assert.AreEqual(false, rod.IsLazyInit); Assert.AreEqual("ChildFactoryMethodName", rod.FactoryMethodName); Assert.AreEqual("ChildFactoryObjectName", rod.FactoryObjectName); Assert.AreEqual("ChildResourceDescription", rod.ResourceDescription); Assert.AreEqual(2, rod.ConstructorArgumentValues.ArgumentCount); Assert.AreEqual(2, rod.PropertyValues.PropertyValues.Count); Assert.AreEqual("Val1", rod.PropertyValues.GetPropertyValue("Prop1").Value); Assert.AreEqual(50, rod.PropertyValues.GetPropertyValue("Age").Value); Assert.AreEqual(2, rod.EventHandlerValues.Events.Count); }
/// <summary> /// Instantiate an instance of the object described by the supplied /// <paramref name="definition"/> from the supplied <paramref name="factory"/>, /// injecting methods as appropriate. /// </summary> /// <remarks> /// <p> /// The default implementation of this method is to throw a /// <see cref="System.InvalidOperationException"/>. /// </p> /// <p> /// Derived classes can override this method if they can instantiate an object /// with the Method Injection specified in the supplied /// <paramref name="definition"/>. Instantiation should use the supplied /// <paramref name="constructor"/> and attendant <paramref name="arguments"/>. /// </p> /// </remarks> /// <param name="definition"> /// The definition of the object that is to be instantiated. /// </param> /// <param name="objectName"> /// The name associated with the object definition. The name can be the null /// or zero length string if we're autowiring an object that doesn't belong /// to the supplied <paramref name="factory"/>. /// </param> /// <param name="factory"> /// The owning <see cref="Oragon.Spring.Objects.Factory.IObjectFactory"/> /// </param> /// <param name="constructor"> /// The <see cref="System.Reflection.ConstructorInfo"/> to be used to instantiate /// the object. /// </param> /// <param name="arguments"> /// Any arguments to the supplied <paramref name="constructor"/>. May be null. /// </param> /// <returns> /// An instance of the object described by the supplied /// <paramref name="definition"/> from the supplied <paramref name="factory"/>. /// </returns> protected virtual object InstantiateWithMethodInjection( RootObjectDefinition definition, string objectName, IObjectFactory factory, ConstructorInfo constructor, object[] arguments) { throw new InvalidOperationException("Method Injection not supported in SimpleInstantiationStrategy"); }