private CompositionResult TrySatisfyImports(ComposablePart part, bool shouldTrackImports) { Assumes.NotNull(part); var result = CompositionResult.SucceededResult; PartManager partManager = GetPartManager(part); var originalState = partManager.State; // Track number of recursive iterations and throw an exception before the stack // fills up and debugging the root cause becomes tricky if (this._recursionStateStack.Count >= MaximumNumberOfCompositionIterations) { return(result.MergeError( ErrorBuilder.ComposeTookTooManyIterations(MaximumNumberOfCompositionIterations))); } // Maintain the stack to detect whether recursive loops cross prerequisites this._recursionStateStack.Push(partManager); try { result = result.MergeResult( TrySatisfyImportsStateMachine(partManager, part)); } finally { this._recursionStateStack.Pop(); } if (shouldTrackImports) { StartSatisfyingImports(partManager, null); } return(result); }
private CompositionResult TrySatisfyImports(PartManager partManager, ComposablePart part, bool shouldTrackImports) { if (part == null) { throw new ArgumentNullException(nameof(part)); } var result = CompositionResult.SucceededResult; // get out if the part is already composed if (partManager.State == ImportState.Composed) { return(result); } // Track number of recursive iterations and throw an exception before the stack // fills up and debugging the root cause becomes tricky if (_recursionStateStack.Count >= MaximumNumberOfCompositionIterations) { return(result.MergeError( ErrorBuilder.ComposeTookTooManyIterations(MaximumNumberOfCompositionIterations))); } // Maintain the stack to detect whether recursive loops cross prerequisites _recursionStateStack.Push(partManager); try { result = result.MergeResult( TrySatisfyImportsStateMachine(partManager, part)); } finally { _recursionStateStack.Pop(); } if (shouldTrackImports) { StartSatisfyingImports(partManager, null); } return(result); }