addObjectInScope method

void addObjectInScope({
  1. required T object,
  2. required String type,
  3. required String scopeId,
  4. bool overrideMainInstance = false,
})

Adds object to given scoped collection

Implementation

void addObjectInScope({
  required T object,
  required String type,
  required String scopeId,
  bool overrideMainInstance = false,
}) {
  if (_instances.containsKey(scopeId)) {
    final scope = _instances[scopeId]!;

    if (scope[type] == null) {
      _instances[scopeId]![type] = [object];
    } else {
      if (overrideMainInstance) {
        _instances[scopeId]![type] = [object];
      } else {
        _instances[scopeId]![type]?.add(object);
      }
    }
  } else {
    _instances[scopeId] = HashMap.from({
      type: [object],
    });
  }
}