reload<S> method
Reloads/restarts a specific registered dependency of type S.
Clears the active dependency object and calls its onDelete lifecycle
before resetting its initialization state.
tagOptional tag to identify the instance.keyOptional unique registry key.forceIf true, reloads even if the instance is marked aspermanent.
Implementation
void reload<S>({String? tag, String? key, bool force = false}) {
final newKey = key ?? _getKey(S, tag);
final builder = _getDependency<S>(tag: tag, key: newKey);
if (builder == null) return;
if (builder.permanent && !force) {
Get.log(
'''Instance "$newKey" is permanent. Use [force = true] to force the restart.''',
isError: true,
);
return;
}
final i = builder.dependency;
if (i is GetxServiceMixin && !force) {
return;
}
if (i is GetLifeCycleMixin) {
i.onDelete();
Get.log('"$newKey" onDelete() called');
}
builder.dependency = null;
builder.isInit = false;
Get.log('Instance "$newKey" was restarted.');
}