visualizeDependencyGraph method
Visualize dependency relationships for debugging
Implementation
String visualizeDependencyGraph(List<ZenScope> scopes) {
final buffer = StringBuffer();
if (!ZenConfig.enableDependencyVisualization) {
return 'Dependency visualization is disabled. Enable it with ZenConfig.enableDependencyVisualization = true';
}
buffer.writeln('=== ZEN DEPENDENCY GRAPH ===\n');
for (final scope in scopes) {
if (scope.isDisposed) continue;
buffer.writeln('SCOPE: ${scope.name ?? scope.id}');
final dependencies = scope.findAllOfType<Object>();
if (dependencies.isEmpty) {
buffer.writeln(' No dependencies registered in this scope\n');
continue;
}
// Group by type for better visualization
final typeGroups = <Type, List<dynamic>>{};
for (final instance in dependencies) {
final type = instance.runtimeType;
typeGroups.putIfAbsent(type, () => []).add(instance);
}
for (final entry in typeGroups.entries) {
final type = entry.key;
final instances = entry.value;
if (instances.length == 1) {
buffer.writeln(' $type');
} else {
buffer.writeln(' $type (${instances.length} instances)');
for (int i = 0; i < instances.length; i++) {
buffer.writeln(' [${i + 1}] ${instances[i].hashCode}');
}
}
}
buffer.writeln();
}
buffer.writeln(
'NOTE: This visualization shows registered dependencies but cannot');
buffer.writeln(
'display actual dependency relationships without constructor analysis.');
return buffer.toString();
}