Exemple #1
0
 public override Expression[] GetExpressions(IContainerContext containerContext, TypeInformation typeInfo, ResolutionContext resolutionContext) =>
 containerContext.Container.ParentContainer.ContainerContext.ResolutionStrategy
 .BuildResolutionExpressions(containerContext.Container.ParentContainer.ContainerContext,
                             resolutionContext.ChildContext == null
             ? resolutionContext.CreateNew(containerContext)
             : resolutionContext,
                             typeInfo);
        public Expression[] GetExpressions(IContainerContext containerContext, TypeInformation typeInfo, ResolutionContext resolutionContext)
        {
            var resolution = resolutionContext.ChildContext == null
                ? resolutionContext.CreateNew(containerContext)
                : resolutionContext.CreateNew(resolutionContext.ChildContext);

            var result = containerContext.Container.ParentContainer.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);
        }
Exemple #3
0
        private Expression PrepareExpression(IContainerContext containerContext, IServiceRegistration serviceRegistration, ResolutionContext resolutionContext, Type resolveType)
        {
            if (serviceRegistration.RegistrationContext.DefinedScopeName != null)
            {
                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)));

                return(this.expressionBuilder.CreateExpression(containerContext,
                                                               serviceRegistration, resolutionContext.CreateNew(scopeParameter:
                                                                                                                new KeyValue <object, ParameterExpression>(serviceRegistration.RegistrationContext.DefinedScopeName, variable)),
                                                               resolveType));
            }

            return(this.expressionBuilder.CreateExpression(containerContext, serviceRegistration, resolutionContext, resolveType));
        }
        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.CreateNew(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);
        }