onInit method
Internal method called by child controllers to auto-register with parent This is called automatically during child controller construction if a parent exists
Implementation
// void _autoRegisterChild(ZenController child) {
// trackController(child);
// }
//
// LIFECYCLE METHODS
//
@mustCallSuper
void onInit() {
if (_initialized) return;
// Save the current parent (for nested controller support)
// This allows proper parent-child tracking even when controllers create other controllers
_savedParent = currentParentController;
// Auto-register with parent if we're being initialized inside another controller's onInit
if (_savedParent != null && !_savedParent!.isDisposed) {
_savedParent!.trackController(this);
ZenLogger.logDebug(
'Controller $runtimeType auto-registered with parent ${_savedParent.runtimeType}');
}
// Set this controller as the current parent for auto-tracking child controllers
// Any queries/mutations/controllers created during onInit will auto-register with this controller
currentParentController = this;
_initialized = true;
ZenLogger.logInfo('Controller $runtimeType initialized');
if (ZenConfig.enablePerformanceMetrics) {
ZenMetrics.incrementCounter('controller.initialized');
}
}