internal override void DoBuildInstance(InjectionContext context, ParameterSet parameters, out T instance) { var matchingContext = context.ForceFindMatchingContext(_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; } else { instance = context.BuildInstance(_process, _description, parameters); } }
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); } }