register<T extends Object> method

void register<T extends Object>(
  1. T? instance, {
  2. String? mark,
})

Register shared objects.

instance -- Shared object to register.

mark -- The unique identifier of the shared object to be registered. If there is only one shared object of the same type in the project, it can be used to distinguish it. Otherwise, it needs to be used to distinguish it.

Implementation

void register<T extends Object>(
  T? instance, {
  String? mark,
}) {
  final Iterable<String> keys = _recordPool.keys;
  final String key = keyGet<T>(mark);
  if (keys.contains(key)) {
    _recordPool.update(key, (value) => instance);
  } else {
    _recordPool.putIfAbsent(key, () => instance);
  }
}