private IActivationExpressionResult GetExpressionFromDependentStrategy(IInjectionScope scope,
                                                                               IActivationExpressionRequest request)
        {
            var newRequest = request.NewRequest(_dependentStrategy.ActivationType, this, request.InjectedType,
                                                request.RequestType, request.Info, true, true);

            var instanceResult = _dependentStrategy.GetActivationExpression(scope, newRequest);

            Expression propertyExpression;

            try
            {
                propertyExpression = Expression.PropertyOrField(instanceResult.Expression, _propertyOrFieldName);
            }
            catch (Exception exp)
            {
                throw new LocateException(request.GetStaticInjectionContext(), exp, $"Could not create property/field expression for {_propertyOrFieldName} on type {instanceResult.Expression.Type.FullName}");
            }

            var expressionResult = request.Services.Compiler.CreateNewResult(request, propertyExpression);

            expressionResult.AddExpressionResult(instanceResult);

            return(expressionResult);
        }
Ejemplo n.º 2
0
        private IActivationExpressionResult GetExpressionFromDependentStrategy(IInjectionScope scope, IActivationExpressionRequest request)
        {
            var newRequest = request.NewRequest(_dependentStrategy.ActivationType, this, request.InjectedType, request.RequestType, request.Info, true, true);

            var instanceResult = _dependentStrategy.GetActivationExpression(scope, newRequest);

            var results = new List <IActivationExpressionResult> {
                instanceResult
            };
            var parameterExpressions = new List <Expression>();

            foreach (var parameterInfo in _methodInfo.GetParameters())
            {
                newRequest = request.NewRequest(parameterInfo.ParameterType, this, _dependentStrategy.ActivationType,
                                                RequestType.MethodParameter, parameterInfo, false, true);

                var parameterResult = request.Services.ExpressionBuilder.GetActivationExpression(scope, newRequest);

                results.Add(parameterResult);
                parameterExpressions.Add(parameterResult.Expression);
            }

            var expression = Expression.Call(instanceResult.Expression, _methodInfo, parameterExpressions);

            var result = request.Services.Compiler.CreateNewResult(request, expression);

            foreach (var expressionResult in results)
            {
                result.AddExpressionResult(expressionResult);
            }

            return(result);
        }
Ejemplo n.º 3
0
 /// <summary>
 /// Gets an activation expression for a given strategy
 /// </summary>
 /// <param name="scope"></param>
 /// <param name="request"></param>
 /// <param name="strategy"></param>
 /// <returns></returns>
 protected virtual IActivationExpressionResult ActivationExpressionForStrategy(IInjectionScope scope, IActivationExpressionRequest request, ICompiledExportStrategy strategy)
 {
     return(strategy.GetActivationExpression(scope, request));
 }