destroy<T extends Object?> method

bool destroy<T extends Object?>({
  1. String? id,
  2. bool onlyInstance = false,
})
inherited

Destroys the instance and builder of T type with an id optional.

If onlyInstance is true, ignores to deresgisters the builder.

Returns true if it was successfully.

Implementation

bool destroy<T extends Object?>({
  String? id,
  bool onlyInstance = false,
}) {
  final instanceRegister = _getInstanceRegister<T>(id);

  if (instanceRegister?.instance == null && onlyInstance) {
    final instanceRef = InstanceRef<T>(id);

    logger.log('The "$instanceRef" instance already deleted.');

    return false;
  }

  if (instanceRegister != null) {
    instanceRegister.refs.clear();
    _removeInstance<T>(instanceRegister);
  }

  if (onlyInstance) return true;

  return unregister<T>(id);
}