Esempio n. 1
0
        /// <summary>
        /// Resolves the instance associated with this hook.
        /// </summary>
        /// <returns>The resolved instance.</returns>
        public object Resolve()
        {
            if (this.Request.ActiveBindings.Contains(this.Binding) &&
                this.IsCyclical(this.Request.ParentContext))
            {
                throw new ActivationException(ExceptionFormatter.CyclicalDependenciesDetected(this));
            }

            try
            {
                this.cachedScope = this.Request.GetScope() ?? this.Binding.GetScope(this);

                if (this.cachedScope != null)
                {
                    lock (this.cachedScope)
                    {
                        return(this.ResolveInternal(this.cachedScope));
                    }
                }
                else
                {
                    return(this.ResolveInternal(null));
                }
            }
            finally
            {
                this.cachedScope = null;
            }
        }
Esempio n. 2
0
        /// <summary>
        ///     Resolves the instance associated with this hook.
        /// </summary>
        /// <returns>The resolved instance.</returns>
        public object Resolve()
        {
            lock (Binding)
            {
                if (Request.ActiveBindings.Contains(Binding))
                {
                    throw new ActivationException(ExceptionFormatter.CyclicalDependenciesDetected(this));
                }

                var cachedInstance = Cache.TryGet(this);

                if (cachedInstance != null)
                {
                    return(cachedInstance);
                }

                Request.ActiveBindings.Push(Binding);

                var reference = new InstanceReference
                {
                    Instance = GetProvider().Create(this)
                };

                Request.ActiveBindings.Pop();

                if (reference.Instance == null)
                {
                    if (!Kernel.Settings.AllowNullInjection)
                    {
                        throw new ActivationException(ExceptionFormatter.ProviderReturnedNull(this));
                    }

                    if (Plan == null)
                    {
                        Plan = Planner.GetPlan(Request.Service);
                    }

                    return(null);
                }

                if (GetScope() != null)
                {
                    Cache.Remember(this, reference);
                }

                if (Plan == null)
                {
                    Plan = Planner.GetPlan(reference.Instance.GetType());
                }

                Pipeline.Activate(this, reference);

                return(reference.Instance);
            }
        }
Esempio n. 3
0
        /// <summary>
        /// Resolves the instance associated with this hook.
        /// </summary>
        /// <returns>The resolved instance.</returns>
        public object Resolve()
        {
            if (Request.ActiveBindings.Contains(Binding))
            {
                throw new ActivationException(ExceptionFormatter.CyclicalDependenciesDetected(this));
            }

            var scope = this.GetScope();

            if (scope != null)
            {
                lock (scope)
                {
                    return(this.ResolveInternal(scope));
                }
            }
            else
            {
                return(this.ResolveInternal(null));
            }
        }