Example #1
0
        /// <summary>
        /// Adds an advice
        /// </summary>
        /// <param name="adviceType"></param>
        /// <param name="pointcut"></param>
        public virtual void AddAdvice(Type adviceType, Func <ISolidMethodConfigurationBuilder, bool> pointcut = null)
        {
            if (adviceType == null)
            {
                throw new ArgumentNullException(nameof(adviceType));
            }
            ConfigureAdvice(adviceType);
            if (pointcut == null)
            {
                // if no pointcut supplied - check if advice has a configuration.
                // the method has to be configured in order for the advice to be added
                var configType = SolidConfigurationHelper.GetAdviceConfigType(adviceType);
                if (configType == null)
                {
                    pointcut = (o) => true;
                }
                else
                {
                    pointcut = (o) => o.IsAdviceConfigured(configType);
                }
            }

            //
            // Add the advice to all the methods that meet the pointcut requirement.
            //
            GetMethodConfigurationBuilders()
            .Where(o => pointcut(o))
            .ToList().ForEach(o => {
                o.AddAdvice(adviceType);
            });
        }
Example #2
0
        private IEnumerable <Type> GetAdviceTypes(Assembly assembly, Type configType)
        {
            var adviceTypes = new HashSet <Type>();

            try
            {
                foreach (var adviceType in assembly.GetTypes())
                {
                    if (!typeof(ISolidProxyInvocationAdvice).IsAssignableFrom(adviceType))
                    {
                        continue;
                    }
                    var adviceConfigType = SolidConfigurationHelper.GetAdviceConfigType(adviceType);
                    if (adviceConfigType == configType)
                    {
                        ConfigureAdvice(adviceType);
                        adviceTypes.Add(adviceType);
                    }
                }
                return(adviceTypes);
            }
            catch (TypeLoadException)
            {
                return(adviceTypes);
            }
        }