internal override void DoBuildInstance(InjectionContext context, ParameterSet parameters, out T instance)
        {
            var matchingContext = context.FindMatchingContext(_description);

            if (matchingContext != null)
            {
                if (!matchingContext.InstanceBuilt)
                {
                    // The current BuildOperation depends on a parent context that has the same ObjectDescription with itself,
                    // yet the parent context does not have a built instance either, that means a cyclic dependency problem.
                    throw CyclicDependencyException(new FakeInjectionContext(context, _description, parameters));
                }

                var myContext = matchingContext as InjectionContext <T>;
                if (myContext == null)
                {
                    throw new ImpossibleException();
                }
                instance = myContext.Instance;

                // If we do find a matching context, then turn this into a shared one.
                InjectionOperatorHelper.UpgradeToSharedObjectBuilder(_builder, new SharedInjectionOperator <T>(_builder, _description, _lifetime, _process));
            }
            else
            {
                instance = context.BuildInstance(_process, _description, parameters);
            }
        }
        // A lock is only needed when the first time an instance is built
        internal override void DoBuildInstance(InjectionContext context, ParameterSet parameters, out T instance)
        {
            var injectionOperator = _builder.InjectionOperator;

            if (!ReferenceEquals(injectionOperator, this))
            {
                _builder.BuildInstance(context, parameters, out instance);
                return;
            }

            Monitor.Enter(_builder.ObjectRelation.SyncRoot);
            injectionOperator = _builder.InjectionOperator;
            if (!ReferenceEquals(injectionOperator, this))
            {
                Monitor.Exit(_builder.ObjectRelation.SyncRoot);
                _builder.BuildInstance(context, parameters, out instance);
                return;
            }

            try
            {
                var process = _configurationSet.CreateInjectionProcess <T>(context.Kernel);
                var oneoff  = new OneOffInjectionOperator <T>(_builder, _description, _lifetime, process);
                InjectionOperatorHelper.UpgradeToOneOffObjectBuilder(_builder, oneoff);
                oneoff.BuildInstance(context, parameters, out instance);
            }
            finally
            {
                Monitor.Exit(_builder.ObjectRelation.SyncRoot);
            }
        }
        internal override void DoBuildInstance(ISharingLifetimeScope scope, ParameterSet parameters, out T instance)
        {
            var context = new ViralSharedInjectionContext <T>(scope, _description, parameters);

            _process.Execute(context);
            instance = context.Instance;
            // replace the ObjectBuilder
            InjectionOperatorHelper.UpgradeToNonSharedObjectBuilder
                (_builder, new NonSharedInjectionOperator <T>(_builder, _description, _lifetime, _process));
        }
        internal override void DoBuildInstance(InjectionContext context, ParameterSet parameters, out T instance)
        {
            var matchingContext = context.ForceFindMatchingContext(_description);

            if (matchingContext != null)
            {
                if (!matchingContext.InstanceBuilt)
                {
                    ////// Replace the temporary one with this, so we won't create an OneOffObjectBuilder any more the next time.
                    ////InjectionOperatorHelper.UpgradeToOneOffObjectBuilder(MyBuilder, this);
                    //if (context.InstanceBuilt)
                    //{
                    //    var newContext = new ViralSharedInjectionContext<T>(context, MyDescription, parameters);
                    //    _process.Execute(newContext);

                    //    var myContext = matchingContext as InjectionContext<T>;
                    //    if (myContext == null)
                    //        throw new ImpossibleException();
                    //    instance = myContext.Instance = newContext.Instance;
                    //}
                    //else

                    // The current BuildOperation depends on a parent context that has the same ObjectDescription with itself,
                    // yet the parent context does not have a built instance either, that means a cyclic dependency problem.
                    throw CyclicDependencyException(new FakeInjectionContext(context, _description, parameters));
                }
                else
                {
                    var myContext = matchingContext as InjectionContext <T>;
                    if (myContext == null)
                    {
                        throw new ImpossibleException();
                    }
                    instance = myContext.Instance;
                    // replace the InjectionOperator
                    InjectionOperatorHelper.UpgradeToSharedObjectBuilder(_builder, new SharedInjectionOperator <T>(_builder, _description, _lifetime, _process));
                }
            }
            else
            {
                // This ObjectBuilder has not built its first instance yet, so we must use a ViralSharedInjectionContext,
                // instead of a NonViralSharedInjectionContext, no matter what kind of InjectionContext the parent context is.
                instance = context.BuildAndShareInstance(_process, _description, parameters);
                // replace the InjectionOperator
                InjectionOperatorHelper.UpgradeToNonSharedObjectBuilder(_builder, new NonSharedInjectionOperator <T>(_builder, _description, _lifetime, _process));
            }
        }