delete<S> method

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

Delete registered Class Instance S (or tag) and, closes any open controllers DisposableInterface, cleans up the memory

/// Deletes the Instance<S>, cleaning the memory. Deletes the Instance<S>, cleaning the memory and closes any open controllers (DisposableInterface).

  • tag Optional "tag" used to register the Instance
  • key For internal usage, is the processed key used to register the Instance. don't use it unless you know what you are doing.
  • force Will delete an Instance even if marked as permanent.

Implementation

//  ///
//  /// - [tag] Optional "tag" used to register the Instance
//  /// - [key] For internal usage, is the processed key used to register
//  ///   the Instance. **don't use** it unless you know what you are doing.

/// Deletes the Instance<[S]>, cleaning the memory and closes any open
/// controllers (`DisposableInterface`).
///
/// - [tag] Optional "tag" used to register the Instance
/// - [key] For internal usage, is the processed key used to register
///   the Instance. **don't use** it unless you know what you are doing.
/// - [force] Will delete an Instance even if marked as `permanent`.
bool delete<S>({String? tag, String? key, bool force = false}) {
  final newKey = key ?? _getKey(S, tag);

  // Check if instance exists
  if (!_singl.containsKey(newKey)) {
    Jet.log('Instance "$newKey" already removed.', isError: true);
    return false;
  }

  final dep = _singl[newKey];
  if (dep == null) return false;

  // Resolve the actual builder to delete (handle dirty instances)
  final builder = _resolveBuilder(dep);

  // Check if deletion is allowed
  if (!_canDelete(builder, newKey, force)) {
    return false;
  }

  // Call lifecycle cleanup
  _callLifecycleCleanup(builder, newKey);

  // Handle deletion based on fenix mode
  return _performDeletion(builder, dep, newKey);
}