reloadAll method
Reloads all registered instances by clearing their active dependency objects and resetting their initialization states.
Each initialized instance receives its onDelete lifecycle (which
triggers onClose) before being cleared, mirroring reload.
Instances marked as permanent and GetxServices are skipped
unless force is true.
forceIf true, reloads even the instances marked aspermanentandGetxServices.
Implementation
void reloadAll({bool force = false}) {
// Iterate over a snapshot of the keys (like [deleteAll]): the `onDelete`
// lifecycle below runs user `onClose` callbacks, which may mutate the
// registry (e.g. `Get.delete<Other>()`, `Get.put`) and would otherwise
// throw a ConcurrentModificationError mid-iteration.
final keys = _singletons.keys.toList();
for (final key in keys) {
final value = _singletons[key];
if (value == null) {
// Removed by a lifecycle callback of a previously reloaded instance.
continue;
}
if (value.permanent && !force) {
Get.log('Instance "$key" is permanent. Skipping reload');
continue;
}
final i = value.dependency;
if (i is GetxServiceMixin && !force) {
Get.log('Instance "$key" is a GetxService. Skipping reload');
continue;
}
if (i is GetLifeCycleMixin) {
i.onDelete();
Get.log('"$key" onDelete() called');
}
value.dependency = null;
value.isInit = false;
Get.log('Instance "$key" was reloaded.');
}
}