Example #1
0
        public void InjectInto(object container, IMemberInjector injectionOverride = null)
        {
            _IsBindingCompleted = true;

            //  Get reflection container for object. Will be performed once per type
            ReflectionCache classReflection = GetReflection(container.GetType());

            //  Inject into fields
            foreach (FieldInfo fieldInfo in classReflection.Fields)
            {
                if (injectionOverride != null && injectionOverride.InjectIntoField(fieldInfo, container))
                {
                    continue;
                }
                else if (InjectIntoField(fieldInfo, container))
                {
                    continue;
                }
                else
                {
                    //  Handler error
                    InjectionError error = CreateError(InjectionErrorType.CanNotFindBindingForType, fieldInfo.FieldType, null, 1);
                    if (_ShouldThrowException)
                    {
                        throw new InjectionException(error.Error, error.Message);
                    }

                    continue;
                }
            }

            //  Inject into properties
            foreach (PropertyInfo propertyInfo in classReflection.Properties)
            {
                if (injectionOverride != null && injectionOverride.InjectIntoProperty(propertyInfo, container))
                {
                    continue;
                }
                else if (InjectIntoProperty(propertyInfo, container))
                {
                    continue;
                }
                else
                {
                    //  Handler error
                    InjectionError error = CreateError(InjectionErrorType.CanNotFindBindingForType, propertyInfo.PropertyType, null, 1);
                    if (_ShouldThrowException)
                    {
                        throw new InjectionException(error.Error, error.Message);
                    }

                    continue;
                }
            }
        }
Example #2
0
        public void InjectInto(object container, IMemberInjector injectionOverride = null)
        {
            _isBindingCompleted = true;

            //  Get reflection container for object. Will be performed once per type
            ReflectionCache classReflection = GetReflection(container.GetType());

            //  Inject into fields
            foreach (FieldInfo fieldInfo in classReflection.Fields)
            {
                //  handle injection overriding, if any
                if (injectionOverride != null && injectionOverride.InjectIntoField(fieldInfo, container))
                {
                    continue;
                }

                //  Get binding for field type
                IInjectionBinding binding;
                if (GetBinding(fieldInfo.FieldType, out binding) == false)
                {
                    continue;
                }

                //  Check restrictions
                if (CheckRestrictions(container, binding) == false)
                {
                    continue;
                }

                //  Inject value
                object value = GetInstanceAndInit(binding.InstanceProvider);
                fieldInfo.SetValue(container, value);
            }

            //  Inject into properties
            foreach (PropertyInfo propertyInfo in classReflection.Properties)
            {
                //  handle injection overriding, if any
                if (injectionOverride != null && injectionOverride.InjectIntoProperty(propertyInfo, container))
                {
                    continue;
                }

                //  Get binding for field type
                IInjectionBinding binding;
                if (GetBinding(propertyInfo.PropertyType, out binding) == false)
                {
                    continue;
                }

                //  Check restrictions
                if (CheckRestrictions(container, binding) == false)
                {
                    continue;
                }

                //  Inject value
                object value = GetInstanceAndInit(binding.InstanceProvider);
                propertyInfo.SetValue(container, value, null);
            }
        }