resolve<T> method

T resolve<T>({
  1. String name = '',
  2. bool singleton = false,
})

Implementation

T resolve<T>({String name = '', bool singleton = false}) {
  if (singleton && _singletons.containsKey(T)) {
    return _singletons[T] as T;
  }
  if (_dependencies.containsKey(T)) {
    final dependencies = _dependencies[T]!;
    if (dependencies.containsKey(name)) {
      final instance = dependencies[name]!;
      if (singleton) {
        _singletons[T] = instance;
      }
      return instance as T;
    }
    throw Exception("Dependency not registered with name '$name': $T");
  }
  throw Exception("Dependency not registered: $T");
}