reload<S> method

void reload<S>({
  1. String? tag,
  2. String? key,
  3. bool force = false,
})

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) {
    debugPrint(
      '''Instance "$newKey" is permanent. Use [force = true] to force the restart.''',
    );
    return;
  }

  final i = builder.dependency;

  if (i is JuneServiceMixin && !force) {
    return;
  }

  if (i is JuneLifeCycleMixin) {
    i.onDelete();
    debugPrint('"$newKey" onDelete() called');
  }

  builder.dependency = null;
  builder.isInit = false;
  debugPrint('Instance "$newKey" was restarted.');
}