Exemplo n.º 1
0
        /// <summary> Add all global interceptors and pointcuts.</summary>
        private void AddGlobalAdvisor(IListableObjectFactory objectFactory, string prefix)
        {
            var globalAspectNames =
                ObjectFactoryUtils.ObjectNamesForTypeIncludingAncestors(objectFactory, typeof(IAdvisors));
            var globalAdvisorNames =
                ObjectFactoryUtils.ObjectNamesForTypeIncludingAncestors(objectFactory, typeof(IAdvisor));
            var globalInterceptorNames =
                ObjectFactoryUtils.ObjectNamesForTypeIncludingAncestors(objectFactory, typeof(IInterceptor));

            List <object> objects             = new List <object>();
            Dictionary <object, string> names = new Dictionary <object, string>();

            for (int i = 0; i < globalAspectNames.Count; i++)
            {
                string name = globalAspectNames[i];
                if (name.StartsWith(prefix))
                {
                    IAdvisors advisors = (IAdvisors)objectFactory.GetObject(name);
                    foreach (object advisor in advisors.Advisors)
                    {
                        // exclude introduction advisors from interceptor list
                        if (!(advisor is IIntroductionAdvisor))
                        {
                            objects.Add(advisor);
                            names[advisor] = name;
                        }
                    }
                }
            }
            for (int i = 0; i < globalAdvisorNames.Count; i++)
            {
                string name = globalAdvisorNames[i];
                if (name.StartsWith(prefix))
                {
                    object obj = objectFactory.GetObject(name);
                    // exclude introduction advisors from interceptor list
                    if (!(obj is IIntroductionAdvisor))
                    {
                        objects.Add(obj);
                        names[obj] = name;
                    }
                }
            }
            for (int i = 0; i < globalInterceptorNames.Count; i++)
            {
                string name = globalInterceptorNames[i];
                if (name.StartsWith(prefix))
                {
                    object obj = objectFactory.GetObject(name);
                    objects.Add(obj);
                    names[obj] = name;
                }
            }
            objects.Sort(OrderComparator.Instance);
            foreach (object obj in objects)
            {
                string name = names[obj];
                AddAdvisorOnChainCreation(obj, name);
            }
        }
        private IDictionary FindAutowireCandidates(string objectName, Type requiredType, DependencyDescriptor descriptor)
        {
            string[] candidateNames =
                ObjectFactoryUtils.ObjectNamesForTypeIncludingAncestors(this, requiredType, true, descriptor.Eager);
#if NET_1_0 || NET_1_1
            IDictionary result = new Hashtable();
#else
            IDictionary result = new OrderedDictionary(candidateNames.Length);
#endif
            foreach (DictionaryEntry entry in resolvableDependencies)
            {
                Type autoWiringType = (Type)entry.Key;
                if (autoWiringType.IsAssignableFrom(requiredType))
                {
                    object autowiringValue = this.resolvableDependencies[autoWiringType];
                    if (requiredType.IsInstanceOfType(autowiringValue))
                    {
                        result.Add(ObjectUtils.IdentityToString(autowiringValue), autowiringValue);
                        break;
                    }
                }
            }
            for (int i = 0; i < candidateNames.Length; i++)
            {
                string candidateName = candidateNames[i];
                if (!candidateName.Equals(objectName) && IsAutowireCandidate(candidateName, descriptor))
                {
                    result.Add(candidateName, GetObject(candidateName));
                }
            }
            return(result);
        }
Exemplo n.º 3
0
        /// <summary> Add all global interceptors and pointcuts.</summary>
        private void AddGlobalAdvisor(IListableObjectFactory objectFactory, string prefix)
        {
            string[] globalAspectNames =
                ObjectFactoryUtils.ObjectNamesForTypeIncludingAncestors(objectFactory, typeof(IAdvisors));
            string[] globalAdvisorNames =
                ObjectFactoryUtils.ObjectNamesForTypeIncludingAncestors(objectFactory, typeof(IAdvisor));
            string[] globalInterceptorNames =
                ObjectFactoryUtils.ObjectNamesForTypeIncludingAncestors(objectFactory, typeof(IInterceptor));
            ArrayList objects = new ArrayList();
            Hashtable names   = new Hashtable();

            for (int i = 0; i < globalAspectNames.Length; i++)
            {
                string name = globalAspectNames[i];
                if (name.StartsWith(prefix))
                {
                    IAdvisors advisors = (IAdvisors)objectFactory.GetObject(name);
                    foreach (object advisor in advisors.Advisors)
                    {
                        // exclude introduction advisors from interceptor list
                        if (!(advisor is IIntroductionAdvisor))
                        {
                            objects.Add(advisor);
                            names[advisor] = name;
                        }
                    }
                }
            }
            for (int i = 0; i < globalAdvisorNames.Length; i++)
            {
                string name = globalAdvisorNames[i];
                if (name.StartsWith(prefix))
                {
                    object obj = objectFactory.GetObject(name);
                    // exclude introduction advisors from interceptor list
                    if (!(obj is IIntroductionAdvisor))
                    {
                        objects.Add(obj);
                        names[obj] = name;
                    }
                }
            }
            for (int i = 0; i < globalInterceptorNames.Length; i++)
            {
                string name = globalInterceptorNames[i];
                if (name.StartsWith(prefix))
                {
                    object obj = objectFactory.GetObject(name);
                    objects.Add(obj);
                    names[obj] = name;
                }
            }
            ((ArrayList)objects).Sort(new OrderComparator());
            foreach (object obj in objects)
            {
                string name = (string)names[obj];
                AddAdvisorOnChainCreation(obj, name);
            }
        }
 /// <summary>
 /// Gets the names of advisor candidates
 /// </summary>
 /// <param name="targetType">the type of the object to be advised</param>
 /// <param name="targetName">the name of the object to be advised</param>
 /// <returns>a non-null string array of advisor candidate names</returns>
 protected virtual IList <string> GetAdvisorCandidateNames(Type targetType, string targetName)
 {
     if (_cachedObjectNames == null)
     {
         lock (this)
         {
             if (_cachedObjectNames == null)
             {
                 List <string>  candidateNameList     = new List <string>();
                 IList <string> advisorCandidateNames = ObjectFactoryUtils.ObjectNamesForTypeIncludingAncestors(_objectFactory, typeof(IAdvisor), true, false);
                 candidateNameList.AddRange(advisorCandidateNames);
                 IList <string> advisorsCandidateNames = ObjectFactoryUtils.ObjectNamesForTypeIncludingAncestors(_objectFactory, typeof(IAdvisors), true, false);
                 candidateNameList.AddRange(advisorsCandidateNames);
                 _cachedObjectNames = candidateNameList;
             }
         }
     }
     return(_cachedObjectNames);
 }
 /// <summary>
 /// Gets the names of advisor candidates
 /// </summary>
 /// <param name="targetType">the type of the object to be advised</param>
 /// <param name="targetName">the name of the object to be advised</param>
 /// <returns>a non-null string array of advisor candidate names</returns>
 protected virtual string[] GetAdvisorCandidateNames(Type targetType, string targetName)
 {
     if (_cachedObjectNames == null)
     {
         lock (this)
         {
             if (_cachedObjectNames == null)
             {
                 ArrayList candidateNameList     = new ArrayList();
                 string[]  advisorCandidateNames = ObjectFactoryUtils.ObjectNamesForTypeIncludingAncestors(_objectFactory, typeof(IAdvisor), true, false);
                 candidateNameList.AddRange(advisorCandidateNames);
                 string[] advisorsCandidateNames = ObjectFactoryUtils.ObjectNamesForTypeIncludingAncestors(_objectFactory, typeof(IAdvisors), true, false);
                 candidateNameList.AddRange(advisorsCandidateNames);
                 _cachedObjectNames = (string[])candidateNameList.ToArray(typeof(string));
             }
         }
     }
     return(_cachedObjectNames);
 }
Exemplo n.º 6
0
        /// <summary> Add all global introductions.</summary>
        private void AddGlobalIntroduction(IListableObjectFactory objectFactory, string prefix)
        {
            IList <string> globalAspectNames =
                ObjectFactoryUtils.ObjectNamesForTypeIncludingAncestors(objectFactory, typeof(IAdvisors));
            IList <string> globalAdvisorNames =
                ObjectFactoryUtils.ObjectNamesForTypeIncludingAncestors(objectFactory, typeof(IAdvisor));
            IList <string> globalIntroductionNames =
                ObjectFactoryUtils.ObjectNamesForTypeIncludingAncestors(objectFactory, typeof(IAdvice));
            ArrayList objects = new ArrayList();
            Dictionary <object, string> names = new Dictionary <object, string>();

            for (int i = 0; i < globalAspectNames.Count; i++)
            {
                string name = globalAspectNames[i];
                if (name.StartsWith(prefix))
                {
                    IAdvisors advisors = (IAdvisors)objectFactory.GetObject(name);
                    foreach (object advisor in advisors.Advisors)
                    {
                        // only include introduction advisors
                        if (advisor is IIntroductionAdvisor)
                        {
                            objects.Add(advisor);
                            names[advisor] = name;
                        }
                    }
                }
            }
            for (int i = 0; i < globalAdvisorNames.Count; i++)
            {
                string name = globalAdvisorNames[i];
                if (name.StartsWith(prefix))
                {
                    object obj = objectFactory.GetObject(name);
                    // only include introduction advisors
                    if (obj is IIntroductionAdvisor)
                    {
                        objects.Add(obj);
                        names[obj] = name;
                    }
                }
            }
            for (int i = 0; i < globalIntroductionNames.Count; i++)
            {
                string name = globalIntroductionNames[i];
                if (name.StartsWith(prefix))
                {
                    object obj = objectFactory.GetObject(name);
                    // exclude other advice types
                    if (!(obj is IInterceptor || obj is IBeforeAdvice || obj is IAfterReturningAdvice))
                    {
                        objects.Add(obj);
                        names[obj] = name;
                    }
                }
            }
            objects.Sort(new OrderComparator());
            foreach (object obj in objects)
            {
                string name = names[obj];
                AddIntroductionOnChainCreation(obj, name);
            }
        }