예제 #1
0
        private Expression PrepareDefaultExpression(ServiceRegistration serviceRegistration, ResolutionContext resolutionContext)
        {
            if (serviceRegistration.RegistrationContext.DefinedScopeName == null)
            {
                return(this.expressionFactory.ConstructExpression(serviceRegistration, resolutionContext));
            }

            var variable = Constants.ResolutionScopeType.AsVariable();

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

            var newScopeContext = resolutionContext.BeginNewScopeContext(new KeyValue <object, ParameterExpression>(serviceRegistration.RegistrationContext.DefinedScopeName, variable));

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

            var expression = this.expressionFactory.ConstructExpression(serviceRegistration, newScopeContext);

            foreach (var definedVariable in newScopeContext.DefinedVariables.Walk())
            {
                resolutionContext.AddDefinedVariable(definedVariable);
            }

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

            return(expression);
        }