get<T> method

T get<T>()

Gets a instance of type T that is registered in the container.

This can initialize this type and return it immediately, or store it for subsequent calls for the singleton case.

Implementation

T get<T>() {
  var type = T;
  var def = _registeredTypes[type];
  if (def == null) {
    _assertOrThrow(
        "Can\'t get type ${type.toString()}: type was not registered");
  }

  if (!def!.single) return def.construct();

  return _instances[type] ?? (_instances[type] = def.construct());
}