public Expression[] GetExpressions(IContainerContext containerContext, TypeInformation typeInfo, ResolutionContext resolutionContext)
        {
            var resolution = resolutionContext.ChildContext == null
                ? resolutionContext.Clone(containerContext)
                : resolutionContext.Clone(resolutionContext.ChildContext);

            var result = containerContext.ResolutionStrategy
                         .BuildResolutionExpressions(containerContext.Container.ParentContainer.ContainerContext, resolution, typeInfo);

            foreach (var definedVariable in resolution.DefinedVariables.Repository)
            {
                resolutionContext.AddDefinedVariable(definedVariable.Key, definedVariable.Value);
            }

            foreach (var instruction in resolution.SingleInstructions)
            {
                resolutionContext.AddInstruction(instruction);
            }

            return(result);
        }
示例#2
0
        private Expression PrepareExpression(IContainerContext containerContext, IServiceRegistration serviceRegistration, ResolutionContext resolutionContext, Type resolveType)
        {
            if (serviceRegistration.RegistrationContext.DefinedScopeName == null)
            {
                return(this.expressionBuilder.CreateExpression(containerContext, serviceRegistration, resolutionContext, resolveType));
            }

            var variable = Constants.ResolutionScopeType.AsVariable();

            var newScope = resolutionContext.CurrentScopeParameter
                           .ConvertTo(Constants.ResolverType)
                           .CallMethod(Constants.BeginScopeMethod,
                                       serviceRegistration.RegistrationContext.DefinedScopeName.AsConstant(),
                                       true.AsConstant());


            resolutionContext.AddDefinedVariable(variable);
            resolutionContext.AddInstruction(variable.AssignTo(newScope.ConvertTo(Constants.ResolutionScopeType)));

            var newContext = resolutionContext.Clone(scopeParameter:
                                                     new KeyValue <object, ParameterExpression>(serviceRegistration.RegistrationContext.DefinedScopeName, variable));

            var expression = this.expressionBuilder.CreateExpression(containerContext, serviceRegistration, newContext, resolveType);

            foreach (var definedVariable in newContext.DefinedVariables.Repository)
            {
                resolutionContext.AddDefinedVariable(definedVariable.Key, definedVariable.Value);
            }

            foreach (var instruction in newContext.SingleInstructions)
            {
                resolutionContext.AddInstruction(instruction);
            }

            return(expression);
        }