コード例 #1
0
 internal ResolutionContext(IEnumerable <object> initialScopeNames,
                            IContainerContext currentContainerContext,
                            bool isRequestedFromRoot,
                            bool nullResultAllowed   = false,
                            bool isValidationRequest = false,
                            HashTree <object, Expression> dependencyOverrides = null,
                            ParameterExpression[] initialParameters           = null)
 {
     this.DefinedVariables      = new Tree <ParameterExpression>();
     this.SingleInstructions    = new ExpandableArray <Expression>();
     this.RemainingDecorators   = new ExpandableArray <Type, Utils.Data.Stack <ServiceRegistration> >();
     this.CurrentDecorators     = new ExpandableArray <ServiceRegistration>();
     this.expressionOverrides   = dependencyOverrides;
     this.NullResultAllowed     = nullResultAllowed;
     IsValidationRequest        = isValidationRequest;
     this.CurrentScopeParameter = Constants.ResolutionScopeParameter;
     this.ParameterExpressions  = initialParameters != null
         ? new ExpandableArray <Pair <bool, ParameterExpression>[]>()
     {
         initialParameters.AsParameterPairs()
     }
         : new ExpandableArray <Pair <bool, ParameterExpression>[]>();
     this.ScopeNames = initialScopeNames.AsStack();
     this.circularDependencyBarrier = new Utils.Data.Stack <int>();
     this.expressionCache           = new Tree <Expression>();
     this.factoryCache                = new Tree <Func <IResolutionScope, object> >();
     this.IsRequestedFromRoot         = isRequestedFromRoot;
     this.CurrentContainerContext     = this.RequestInitiatorContainerContext = currentContainerContext;
     this.FactoryDelegateCacheEnabled = this.PerResolutionRequestCacheEnabled = dependencyOverrides == null;
     this.IsTopRequest                = true;
 }
コード例 #2
0
        internal ResolutionContext BeginDecoratingContext(Type decoratingType, Utils.Data.Stack <ServiceRegistration> serviceRegistrations)
        {
            var clone    = this.Clone();
            var newStack = new Utils.Data.Stack <ServiceRegistration>(serviceRegistrations);
            var current  = newStack.Pop();

            clone.CurrentDecorators = new ExpandableArray <ServiceRegistration>(this.CurrentDecorators);
            clone.CurrentDecorators.Add(current);
            clone.RemainingDecorators = new ExpandableArray <Type, Utils.Data.Stack <ServiceRegistration> >(this.RemainingDecorators);
            clone.RemainingDecorators.AddOrUpdate(decoratingType, newStack);
            return(clone);
        }
コード例 #3
0
        private Expression BuildExpressionForDecorator(ServiceRegistration serviceRegistration,
                                                       ResolutionContext resolutionContext, Type requestedType, Utils.Data.Stack <ServiceRegistration> decorators)
        {
            if (serviceRegistration is OpenGenericRegistration openGenericRegistration)
            {
                serviceRegistration = openGenericRegistration.ProduceClosedRegistration(requestedType);
            }

            return(this.BuildExpressionAndApplyLifetime(serviceRegistration, resolutionContext,
                                                        requestedType, decorators.PeekBack()?.RegistrationContext.Lifetime));
        }