dependency<U> method

U dependency<U>({
  1. bool existingInstance = true,
})

Implementation

U dependency<U>({bool existingInstance = true}) {
  final key = _factory.keys.firstWhere((element) => reflectClass(element).isSubtypeOf(reflectClass(U)));
  if (existingInstance) {
    if (_cache[key] == null) {
      _cache[key] = _factory[key]!();
    }
    return _cache[key]! as U;
  } else {
    return _factory[key]!() as U;
  }
}