getBind<T extends Object> method

T? getBind<T extends Object>({
  1. required List<Type> typesInRequest,
})

Implementation

T? getBind<T extends Object>({required List<Type> typesInRequest}) {
  T bindValue;
  var type = _getInjectType<T>();
  if (_singletonBinds.containsKey(type)) {
    bindValue = _singletonBinds[type];
    return bindValue;
  }

  var bind = _binds.firstWhere((b) => b.inject is T Function(Inject), orElse: () => BindEmpty());
  if (bind is BindEmpty) {
    typesInRequest.remove(type);
    return null;
  }

  if (typesInRequest.contains(type)) {
    throw ModularError('''
Recursive calls detected. This can cause StackOverflow.
Check the Binds of the $runtimeType module:
***
${typesInRequest.join('\n')}
***

    ''');
  } else {
    typesInRequest.add(type);
  }

  bindValue = bind.inject(Inject(typesInRequest: typesInRequest)) as T;
  if (bind.isSingleton) {
    _singletonBinds[type] = bindValue;
  }

  typesInRequest.remove(type);
  return bindValue;
}