clear method
void
clear()
Clear all dependencies
Implementation
void clear() {
final dependencies = _scope.getAllDependencies();
for (final dependency in dependencies) {
try {
// Try to dispose if it's a controller
if (dependency is ZenController && !dependency.isDisposed) {
dependency.dispose();
}
} catch (e) {
// Continue clearing even if some fail
if (ZenConfig.enableDebugLogs) {
ZenLogger.logDebug(
'Failed to dispose dependency ${dependency.runtimeType}: $e');
}
}
}
// Clear the scope's dependencies by getting their types and deleting
final allDeps = _scope.getAllDependencies();
for (final dep in allDeps) {
final tag = _scope.getTagForInstance(dep);
if (tag != null) {
_scope.deleteByTag(tag, force: true);
} else {
_scope.deleteByType(dep.runtimeType, force: true);
}
}
if (ZenConfig.enableDebugLogs) {
ZenLogger.logDebug('Cleared all dependencies from test container');
}
}