replace<P> method

void replace<P>(
  1. P child, {
  2. String? tag,
})

Replaces an existing registered instance of type P with a new child instance.

If the existing instance is permanent, it will be forcefully deleted first before the new child is registered.

Registrations that delete intentionally keeps alive (a fenix factory kept for resurrection, a GetxService, or an entry whose lateRemove disposal is still pending) are evicted outright, so the new child always takes their place.

  • tag Optional tag to identify the instance.

Implementation

void replace<P>(P child, {String? tag}) {
  final info = getInstanceInfo<P>(tag: tag);
  final permanent = (info.isPermanent ?? false);
  delete<P>(tag: tag, force: permanent);
  _evictSurvivingRegistration(_getKey(P, tag));
  put(child, tag: tag, permanent: permanent);
}