internal string VisualizeIndentedObjectGraph(int indentingDepth, HashSet<InstanceProducer> set = null)
        {
            set = set ?? new HashSet<InstanceProducer>(ReferenceEqualityComparer<InstanceProducer>.Instance);

            var visualizedDependencies =
                from relationship in this.GetRelationships()
                let dependency = relationship.Dependency
                let isCyclicGraph = set.Contains(dependency)
                let visualizeSubGraph = isCyclicGraph
                    ? dependency.VisualizeCyclicProducerWithoutDependencies(indentingDepth + 1)
                    : set.AddReturn(dependency).VisualizeIndentedObjectGraph(indentingDepth + 1, set)
                select Environment.NewLine + visualizeSubGraph;

            return string.Format(CultureInfo.InvariantCulture, "{0}{1}({2})",
                new string(' ', indentingDepth * 4),
                this.ImplementationType.ToFriendlyName(),
                string.Join(",", visualizedDependencies));
        }
Example #2
0
        private static IEnumerable<InstanceProducer> GetSelfAndDependentProducers(InstanceProducer producer,
            HashSet<InstanceProducer> set = null)
        {
            set = set ?? new HashSet<InstanceProducer>(ReferenceEqualityComparer<InstanceProducer>.Instance);

            // Prevent stack overflow exception in case the graph is cyclic.
            if (set.Contains(producer))
            {
                yield break;
            }

            // Return self
            yield return set.AddReturn(producer);

            // Return dependent producers
            foreach (var relationship in producer.GetRelationships())
            {
                yield return set.AddReturn(relationship.Dependency);

                foreach (var dependentProducer in GetSelfAndDependentProducers(relationship.Dependency, set))
                {
                    yield return set.AddReturn(dependentProducer);
                }
            }
        }