コード例 #1
0
        /// <summary>
        /// Creates a new <see cref="ObjectDefinitionBuilder"/> used to construct a <see cref="Oragon.Spring.Objects.Factory.Support.GenericObjectDefinition"/>.
        /// </summary>
        public static ObjectDefinitionBuilder GenericObjectDefinition()
        {
            ObjectDefinitionBuilder builder = new ObjectDefinitionBuilder();

            builder.objectDefinition = new GenericObjectDefinition();
            return(builder);
        }
コード例 #2
0
        /// <summary>
        /// Creates a new <see cref="ObjectDefinitionBuilder"/> used to construct a <see cref="Oragon.Spring.Objects.Factory.Support.GenericObjectDefinition"/>.
        /// </summary>
        /// <param name="objectTypeName">the name of the <see cref="Type"/> of the object that the definition is being created for</param>
        public static ObjectDefinitionBuilder GenericObjectDefinition(string objectTypeName)
        {
            ObjectDefinitionBuilder builder = new ObjectDefinitionBuilder();

            builder.objectDefinition = new GenericObjectDefinition();
            builder.objectDefinition.ObjectTypeName = objectTypeName;
            return(builder);
        }
コード例 #3
0
        public void ObjectType()
        {
            ObjectDefinitionBuilder odb = ObjectDefinitionBuilder.RootObjectDefinition(odf, typeof(TestObject));
            RootObjectDefinition    rod = odb.ObjectDefinition as RootObjectDefinition;

            Assert.IsNotNull(rod);
            Assert.IsTrue(rod.HasObjectType);
            Assert.AreEqual(typeof(TestObject), rod.ObjectType);
        }
コード例 #4
0
        public void ObjectNameChild()
        {
            ObjectDefinitionBuilder odb = ObjectDefinitionBuilder.ChildObjectDefinition(odf, typeof(TestObject).FullName);
            ChildObjectDefinition   rod = odb.ObjectDefinition as ChildObjectDefinition;

            Assert.IsNotNull(rod);
            Assert.IsFalse(rod.HasObjectType);
            Assert.AreEqual(typeof(TestObject).FullName, rod.ParentName);
        }
コード例 #5
0
        public void Simple()
        {
            GenericApplicationContext ctx = new GenericApplicationContext();
            IObjectDefinitionFactory  objectDefinitionFactory = new DefaultObjectDefinitionFactory();

            ObjectDefinitionBuilder builder = ObjectDefinitionBuilder.RootObjectDefinition(objectDefinitionFactory,
                                                                                           typeof(TestObject));

            builder.AddPropertyValue("Age", 22)
            .AddPropertyValue("Name", "Joe")
            .AddPropertyReference("Spouse", "Spouse")
            .SetSingleton(false);

            ctx.RegisterObjectDefinition("TestObject", builder.ObjectDefinition);

            builder = ObjectDefinitionBuilder.RootObjectDefinition(objectDefinitionFactory, typeof(TestObject));

            IList friends = new ArrayList();

            friends.Add(new TestObject("Dan", 34));
            friends.Add(new TestObject("Mary", 33));
            builder.AddPropertyValue("Friends", friends)
            .AddConstructorArg("Susan")
            .AddConstructorArg(23)
            .SetSingleton(false);

            ctx.RegisterObjectDefinition("Spouse", builder.ObjectDefinition);



            TestObject to = ctx.GetObject("TestObject") as TestObject;

            Assert.IsNotNull(to);

            Assert.AreEqual("Joe", to.Name);
            Assert.AreEqual(22, to.Age);
            Assert.AreEqual(2, to.Spouse.Friends.Count);
            Assert.AreEqual(23, to.Spouse.Age);

            /*
             * AbstractApplicationContext ctx = ContextRegistry.GetContext() as AbstractApplicationContext;
             *
             *
             *
             * //XmlObjectFactory objectFactory = ctx.ObjectFactory as XmlObjectFactory;
             *
             * IObjectFactory objectFactory = ctx.ObjectFactory;
             *
             * //DefaultListableObjectFactory
             * if (objectFactory != null)
             * {
             *  Console.WriteLine("hi");
             * }
             * //objectFactory.RegisterObjectDefinition("TestObject", builder.ObjectDefinition);
             */
        }
コード例 #6
0
        public void ObjectTypeWithFactoryMethod()
        {
            ObjectDefinitionBuilder odb =
                ObjectDefinitionBuilder.RootObjectDefinition(odf, typeof(TestObject), "Create");
            RootObjectDefinition rod = odb.ObjectDefinition as RootObjectDefinition;

            Assert.IsNotNull(rod);
            Assert.IsTrue(rod.HasObjectType);
            Assert.AreEqual(typeof(TestObject), rod.ObjectType);
            Assert.AreEqual("Create", rod.FactoryMethodName);
        }
コード例 #7
0
        /// <summary>
        /// Create a new <code>ObjectDefinitionBuilder</code> used to construct a child object definition..
        /// </summary>
        /// <param name="objectDefinitionFactory">The object definition factory.</param>
        /// <param name="parentObjectName">Name of the parent object.</param>
        /// <returns></returns>
        public static ObjectDefinitionBuilder ChildObjectDefinition(IObjectDefinitionFactory objectDefinitionFactory,
                                                                    string parentObjectName)
        {
            ObjectDefinitionBuilder builder = new ObjectDefinitionBuilder();

            builder.objectDefinitionFactory = objectDefinitionFactory;

            builder.objectDefinition =
                objectDefinitionFactory.CreateObjectDefinition(null, parentObjectName, AppDomain.CurrentDomain);

            return(builder);
        }
コード例 #8
0
        /// <summary>
        /// Create a new <code>ObjectDefinitionBuilder</code> used to construct a root object definition.
        /// </summary>
        /// <param name="objectDefinitionFactory">The object definition factory.</param>
        /// <param name="objectType">Type of the object.</param>
        /// <param name="factoryMethodName">Name of the factory method.</param>
        /// <returns>A new <code>ObjectDefinitionBuilder</code> instance.</returns>
        public static ObjectDefinitionBuilder RootObjectDefinition(IObjectDefinitionFactory objectDefinitionFactory,
                                                                   Type objectType, string factoryMethodName)
        {
            ObjectDefinitionBuilder builder = new ObjectDefinitionBuilder();

            builder.objectDefinitionFactory = objectDefinitionFactory;

            builder.objectDefinition =
                objectDefinitionFactory.CreateObjectDefinition(objectType.FullName, null, AppDomain.CurrentDomain);

            builder.objectDefinition.ObjectType        = objectType;
            builder.objectDefinition.FactoryMethodName = factoryMethodName;
            return(builder);
        }
コード例 #9
0
        /// <summary>
        /// Create a new <code>ObjectDefinitionBuilder</code> used to construct a root object definition.
        /// </summary>
        /// <param name="objectDefinitionFactory">The object definition factory.</param>
        /// <param name="objectTypeName">Name of the object type.</param>
        /// <param name="factoryMethodName">Name of the factory method.</param>
        /// <returns>A new <code>ObjectDefinitionBuilder</code> instance.</returns>
        public static ObjectDefinitionBuilder RootObjectDefinition(IObjectDefinitionFactory objectDefinitionFactory,
                                                                   string objectTypeName,
                                                                   string factoryMethodName)
        {
            ObjectDefinitionBuilder builder = new ObjectDefinitionBuilder();

            builder.objectDefinitionFactory = objectDefinitionFactory;

            // Pass in null for parent name and also AppDomain to force object definition to be register by name and not type.
            builder.objectDefinition =
                objectDefinitionFactory.CreateObjectDefinition(objectTypeName, null, null);

            builder.objectDefinition.FactoryMethodName = factoryMethodName;

            return(builder);
        }
コード例 #10
0
        public void ObjectTypeWithSimpleProperty()
        {
            string[] dependsOn          = new string[] { "A", "B", "C" };
            ObjectDefinitionBuilder odb = ObjectDefinitionBuilder.RootObjectDefinition(odf, typeof(TestObject));

            odb.SetSingleton(false).AddPropertyReference("Age", "15");
            foreach (string dep in dependsOn)
            {
                odb.AddDependsOn(dep);
            }

            RootObjectDefinition rod = odb.ObjectDefinition as RootObjectDefinition;

            Assert.IsNotNull(rod);
            Assert.IsFalse(rod.IsSingleton);
            Assert.AreEqual(typeof(TestObject), rod.ObjectType);
            Assert.AreEqual(dependsOn, rod.DependsOn, "DependsOn not as expected");
            Assert.IsTrue(rod.PropertyValues.Contains("Age"));
        }