Ejemplo n.º 1
0
        /// <summary>
        /// Applies user supplied override values to instance properties.
        /// </summary>
        /// <param name="context">The context.</param>
        /// <param name="reference">A reference to the instance being activated.</param>
        /// <param name="propertyValues">The parameter override value accessors.</param>
        /// <exception cref="ActivationException">A given <see cref="IPropertyValue"/> cannot be resolved to a property of the specified instance.</exception>
        private void AssignPropertyOverrides(IContext context, InstanceReference reference, List <IPropertyValue> propertyValues)
        {
            var properties = reference.Instance.GetType().GetProperties(this.Flags);

            foreach (var propertyValue in propertyValues)
            {
                var propertyInfo = FindPropertyByName(properties, propertyValue.Name, StringComparison.Ordinal);

                if (propertyInfo == null)
                {
                    throw new ActivationException(this.exceptionFormatter.CouldNotResolvePropertyForValueInjection(context.Request, propertyValue.Name));
                }

                var target = new PropertyInjectionDirective(propertyInfo, this.injectorFactory.Create(propertyInfo));
                var value  = propertyValue.GetValue(context, target.Target);
                target.Injector(reference.Instance, value);
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Applies user supplied override values to instance properties.
        /// </summary>
        /// <param name="context">The context.</param>
        /// <param name="reference">A reference to the instance being activated.</param>
        /// <param name="propertyValues">The parameter override value accessors.</param>
        private void AssignPropertyOverrides(IContext context, InstanceReference reference, IList <IPropertyValue> propertyValues)
        {
            var properties = reference.Instance.GetType().GetRuntimeProperties().FilterPublic(Settings.InjectNonPublic);

            foreach (var propertyValue in propertyValues)
            {
                string propertyName = propertyValue.Name;
                var    propertyInfo = properties.FirstOrDefault(property => string.Equals(property.Name, propertyName, StringComparison.Ordinal));

                if (propertyInfo == null)
                {
                    throw new ActivationException(ExceptionFormatter.CouldNotResolvePropertyForValueInjection(context.Request, propertyName));
                }

                var    target = new PropertyInjectionDirective(propertyInfo, this.InjectorFactory.Create(propertyInfo));
                object value  = this.GetValue(context, target.Target, propertyValues);
                target.Injector(reference.Instance, value);
            }
        }
        /// <summary>
        /// Applies user supplied override values to instance properties.
        /// </summary>
        /// <param name="context">The context.</param>
        /// <param name="reference">A reference to the instance being activated.</param>
        /// <param name="propertyValues">The parameter ovverride value accessors.</param>
        private void AssignProperyOverrides(IContext context, InstanceReference reference, IEnumerable <IParameter> propertyValues)
        {
            var properties = reference.Instance.GetType().GetProperties(Flags);

            foreach (var propertyValue in propertyValues)
            {
                string propertyName = propertyValue.Name;
                var    propertyInfo = properties
                                      .Where(property => string.Equals(property.Name, propertyName, StringComparison.Ordinal))
                                      .FirstOrDefault();

                if (propertyInfo == null)
                {
                    throw new ActivationException(ExceptionFormatter.CouldNotResolveProperyForValueInjection(context.Request, propertyName));
                }

                var    target = new PropertyInjectionDirective(propertyInfo, InjectorFactory.Create(propertyInfo));
                object value  = GetValue(context, target.Target);
                target.Injector(reference.Instance, value);
            }
        }