private Expression WrapWithPropertyInjectorInternal(
            Type implementationType, Expression expressionToWrap)
        {
            PropertyInfo[] properties = this.GetPropertiesToInject(implementationType);

            if (properties.Length > 0)
            {
                PropertyInjectionHelper.VerifyProperties(properties);

                var data = PropertyInjectionHelper.BuildPropertyInjectionExpression(
                    this.Container, implementationType, properties, expressionToWrap);

                expressionToWrap = data.Expression;

                var knownRelationships =
                    from pair in data.Producers.Zip(data.Properties, (prod, prop) => new { prod, prop })
                    select new KnownRelationship(
                        implementationType: implementationType,
                        lifestyle: this.Lifestyle,
                        consumer: new InjectionConsumerInfo(implementationType, pair.prop !),
                        dependency: pair.prod !);

                foreach (var knownRelationship in knownRelationships)
                {
                    this.AddRelationship(knownRelationship);
                }
            }

            return(expressionToWrap);
        }
        private Expression WrapWithPropertyInjectorInternal(Type serviceType, Type implementationType,
                                                            Expression expression)
        {
            var properties = this.GetPropertiesToInject(serviceType, implementationType);

            if (properties.Any())
            {
                PropertyInjectionHelper.VerifyProperties(properties);

                expression = PropertyInjectionHelper.BuildPropertyInjectionExpression(
                    this.Container, serviceType, implementationType, properties, expression);

                this.AddPropertiesAsKnownRelationships(serviceType, implementationType, properties);
            }

            return(expression);
        }
        private Func <object, object> BuildDelegate()
        {
            PropertyInfo[] propertiesToInject = this.GetInjectableProperties();

            var dummyExpression = Expression.Constant(null, this.Type);

            var propertyInjectionExpression = PropertyInjectionHelper.BuildPropertyInjectionExpression(
                this.container, this.Type, propertiesToInject, dummyExpression);

            var parameter = Expression.Parameter(typeof(object));

            propertyInjectionExpression = SubExpressionReplacer.Replace(
                expressionToAlter: propertyInjectionExpression,
                subExpressionToFind: dummyExpression,
                replacementExpression: Expression.Convert(parameter, this.Type));

            return(Expression.Lambda <Func <object, object> >(propertyInjectionExpression, parameter).Compile());
        }
Beispiel #4
0
        private Expression WrapWithPropertyInjectorInternal(Type implementationType,
                                                            Expression expressionToWrap)
        {
            PropertyInfo[] properties = this.GetPropertiesToInject(implementationType);

            if (properties.Any())
            {
                PropertyInjectionHelper.VerifyProperties(properties);

                var data = PropertyInjectionHelper.BuildPropertyInjectionExpression(
                    this.Container, implementationType, properties, expressionToWrap);

                expressionToWrap = data.Expression;

                this.AddRelationships(implementationType, data.Producers);
            }

            return(expressionToWrap);
        }