registerInstance<T> method

void registerInstance<T>(
  1. T instance,
  2. String? tag
)

Register an instance

Implementation

void registerInstance<T>(T instance, String? tag) {
  // Store the instance by its exact generic type T
  _instances.putIfAbsent(T, () => {});
  _instances[T]![tag] = instance;

  // Also store by runtime type if it's different from T
  final runtimeType = instance.runtimeType;
  if (runtimeType != T) {
    _instances.putIfAbsent(runtimeType, () => {});
    _instances[runtimeType]![tag] = instance;
  }
}