lazyReplace<P> method

void lazyReplace<P>(
  1. InstanceBuilderCallback<P> builder, {
  2. String? tag,
  3. bool? fenix,
})

Replaces an existing registered dependency of type P with a new lazy factory builder.

If the existing instance is permanent, it will be forcefully deleted first.

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 builder always takes their place.

  • tag Optional tag to identify the instance.
  • fenix If true, the builder callback will persist in memory to recreate the instance if deleted. If not provided, defaults to true if the parent instance was permanent.

Implementation

void lazyReplace<P>(
  InstanceBuilderCallback<P> builder, {
  String? tag,
  bool? fenix,
}) {
  final info = getInstanceInfo<P>(tag: tag);
  final permanent = (info.isPermanent ?? false);
  delete<P>(tag: tag, force: permanent);
  _evictSurvivingRegistration(_getKey(P, tag));
  lazyPut(builder, tag: tag, fenix: fenix ?? permanent);
}