예제 #1
0
        /// <summary>
        /// Return all objects of the given type or subtypes, also picking up objects
        /// defined in ancestor object factories if the current object factory is an
        /// <see cref="Spring.Objects.Factory.IHierarchicalObjectFactory"/>.
        /// </summary>
        /// <remarks>
        /// <p>
        /// The return list will only contain objects of this type.
        /// Useful convenience method when we don't care about object names.
        /// </p>
        /// </remarks>
        /// <param name="factory">The object factory.</param>
        /// <param name="type">The <see cref="System.Type"/> of object to match.</param>
        /// <param name="includePrototypes">
        /// Whether to include prototype objects too or just singletons
        /// (also applies to <see cref="Spring.Objects.Factory.IFactoryObject"/> instances).
        /// </param>
        /// <param name="includeFactoryObjects">
        /// Whether to include <see cref="Spring.Objects.Factory.IFactoryObject"/> instances
        /// too or just normal objects.
        /// </param>
        /// <exception cref="Spring.Objects.ObjectsException">
        /// If the objects could not be created.
        /// </exception>
        /// <returns>
        /// The <see cref="System.Collections.IDictionary"/> of object instances, or an
        /// empty <see cref="System.Collections.IDictionary"/> if none.
        /// </returns>
        public static Dictionary <string, object> ObjectsOfTypeIncludingAncestors(
            IListableObjectFactory factory, Type type,
            bool includePrototypes, bool includeFactoryObjects)
        {
            Dictionary <string, object> result = new Dictionary <string, object>();

            foreach (var entry in factory.GetObjectsOfType(type, includePrototypes, includeFactoryObjects))
            {
                result.Add(entry.Key, entry.Value);
            }

            IListableObjectFactory pof = GetParentListableObjectFactoryIfAny(factory);

            if (pof != null)
            {
                IHierarchicalObjectFactory  hof          = (IHierarchicalObjectFactory)factory;
                Dictionary <string, object> parentResult = ObjectsOfTypeIncludingAncestors(pof, type, includePrototypes, includeFactoryObjects);
                foreach (string objectName in parentResult.Keys)
                {
                    if (!result.ContainsKey(objectName) && !hof.ContainsLocalObject(objectName))
                    {
                        result.Add(objectName, parentResult[objectName]);
                    }
                }
            }
            return(result);
        }
예제 #2
0
        /// <summary>
        /// Get all object names for the given type, including those defined in ancestor
        /// factories.
        /// </summary>
        /// <remarks>
        /// <p>
        /// Will return unique names in case of overridden object definitions.
        /// </p>
        /// <p>
        /// Does consider objects created by <see cref="Spring.Objects.Factory.IFactoryObject"/>s,
        /// or rather it considers the type of objects created by
        /// <see cref="Spring.Objects.Factory.IFactoryObject"/> (which means that
        /// <see cref="Spring.Objects.Factory.IFactoryObject"/>s will be instantiated).
        /// </p>
        /// </remarks>
        /// <param name="factory">
        /// If this isn't also an
        /// <see cref="Spring.Objects.Factory.IHierarchicalObjectFactory"/>,
        /// this method will return the same as it's own
        /// <see cref="Spring.Objects.Factory.IListableObjectFactory.GetObjectDefinitionNames"/>
        /// method.
        /// </param>
        /// <param name="type">
        /// The <see cref="System.Type"/> that objects must match.
        /// </param>
        /// <returns>
        /// The array of object names, or an empty array if none.
        /// </returns>
        public static IList <string> ObjectNamesForTypeIncludingAncestors(
            IListableObjectFactory factory, Type type)
        {
            List <string> result = new List <string>();

            result.AddRange(factory.GetObjectNamesForType(type));
            IListableObjectFactory pof = GetParentListableObjectFactoryIfAny(factory);

            if (pof != null)
            {
                IHierarchicalObjectFactory hof           = (IHierarchicalObjectFactory)factory;
                IList <string>             parentsResult = ObjectNamesForTypeIncludingAncestors(pof, type);
                foreach (string objectName in parentsResult)
                {
                    if (!result.Contains(objectName) && !hof.ContainsLocalObject(objectName))
                    {
                        result.Add(objectName);
                    }
                }
            }
            return(result);
        }
예제 #3
0
        /// <summary>
        /// Get all object names for the given type, including those defined in ancestor
        /// factories.
        /// </summary>
        /// <remarks>
        /// <p>
        /// Will return unique names in case of overridden object definitions.
        /// </p>
        /// <p>
        /// Does consider objects created by <see cref="Spring.Objects.Factory.IFactoryObject"/>s
        /// if <paramref name="includeFactoryObjects"/> is set to true,
        /// which means that <see cref="Spring.Objects.Factory.IFactoryObject"/>s will get initialized.
        /// </p>
        /// </remarks>
        /// <param name="factory">
        /// If this isn't also an
        /// <see cref="Spring.Objects.Factory.IHierarchicalObjectFactory"/>,
        /// this method will return the same as it's own
        /// <see cref="Spring.Objects.Factory.IListableObjectFactory.GetObjectDefinitionNames"/>
        /// method.
        /// </param>
        /// <param name="type">
        /// The <see cref="System.Type"/> that objects must match.
        /// </param>
        /// <param name="includePrototypes">
        /// Whether to include prototype objects too or just singletons
        /// (also applies to <see cref="Spring.Objects.Factory.IFactoryObject"/> instances).
        /// </param>
        /// <param name="includeFactoryObjects">
        /// Whether to include <see cref="Spring.Objects.Factory.IFactoryObject"/> instances
        /// too or just normal objects.
        /// </param>
        /// <returns>
        /// The array of object names, or an empty array if none.
        /// </returns>
        public static string[] ObjectNamesForTypeIncludingAncestors(
            IListableObjectFactory factory, Type type,
            bool includePrototypes, bool includeFactoryObjects)
        {
            ArrayList result = new ArrayList();

            result.AddRange(factory.GetObjectNamesForType(type, includePrototypes, includeFactoryObjects));
            IListableObjectFactory pof = GetParentListableObjectFactoryIfAny(factory);

            if (pof != null)
            {
                IHierarchicalObjectFactory hof = (IHierarchicalObjectFactory)factory;
                string[] parentsResult         = ObjectNamesForTypeIncludingAncestors(pof, type, includePrototypes, includeFactoryObjects);
                foreach (string objectName in parentsResult)
                {
                    if (!result.Contains(objectName) && !hof.ContainsLocalObject(objectName))
                    {
                        result.Add(objectName);
                    }
                }
            }
            return((string[])result.ToArray(typeof(string)));
        }