Esempio n. 1
0
        private static void MergeBinding(IBindingConfig bindingConfig, IBindingConfig explicitBindingConfig)
        {
            // merge constructor
            if (explicitBindingConfig.Constructor != null)
            {
                bindingConfig.Constructor = explicitBindingConfig.Constructor;
            }

            // merge factory
            if (explicitBindingConfig.FactoryExpression != null)
            {
                bindingConfig.FactoryExpression = explicitBindingConfig.FactoryExpression;
            }

            // merge lifestyle
            if (explicitBindingConfig.Lifestyle != null)
            {
                bindingConfig.Lifestyle = explicitBindingConfig.Lifestyle;
            }

            foreach (var fis in explicitBindingConfig.GetFieldInfoSetters())
            {
                bindingConfig.SetFieldInfoSetter(fis.MemberInfo, fis.MemberSetter);
            }

            foreach (var pis in explicitBindingConfig.GetPropertyInfoSetters())
            {
                bindingConfig.SetPropertyInfoSetter(pis.MemberInfo, pis.MemberSetter);
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Adds the property injector to binding config.
        /// </summary>
        /// <param name="bindingConfig">Binding config.</param>
        /// <param name="propertyExpression">Property expression.</param>
        /// <param name="setter">Setter.</param>
        /// <typeparam name="CType">The 1st type parameter.</typeparam>
        /// <typeparam name="TPropertyType">The 2nd type parameter.</typeparam>
        internal static void AddMemberInjectorToBindingConfig <CType, TPropertyType>(
            IBindingConfig bindingConfig,
            Expression <Func <CType, TPropertyType> > propertyExpression,
            Expression <Func <TPropertyType> > setter)
            where CType : class
        {
            var memberExpression = propertyExpression.Body as MemberExpression;

            if (memberExpression == null)
            {
                throw InjectorErrors.ErrorMustContainMemberExpression.FormatEx("memberExpression");
            }

            var member = memberExpression.Member;

            if (member is PropertyInfo)
            {
                bindingConfig.SetPropertyInfoSetter(member as PropertyInfo, setter);
            }
            else if (member is FieldInfo)
            {
                bindingConfig.SetFieldInfoSetter(member as FieldInfo, setter);
            }
            else
            {
                // Should not be reachable.
                throw InjectorErrors.ErrorMustContainMemberExpression.FormatEx("memberExpression");
            }
        }