Activate() публичный Метод

Activates the instance in the specified context.
public Activate ( IContext context, InstanceReference reference ) : void
context IContext The context.
reference InstanceReference The instance reference.
Результат void
Пример #1
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 (!this.Kernel.Settings.AllowNullInjection)
                    {
                        throw new ActivationException(ExceptionFormatter.ProviderReturnedNull(this));
                    }

                    if (this.Plan == null)
                    {
                        this.Plan = this.Planner.GetPlan(this.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;
            }
        }