find<T> static method

T find<T>()

Retrieves the registered instance of type T, or creates one via factory.

Throws if no instance or factory is found.

Implementation

static T find<T>() {
  if (_instances.containsKey(T)) {
    _notify('find', T);
    return _instances[T] as T;
  } else if (_factories.containsKey(T)) {
    final instance = _factories[T]!();
    return put<T>(instance);
  } else {
    throw Exception("No instance of $T found.");
  }
}