resolve<T> method

T resolve<T>([
  1. String? name
])

Attemps to resolve the type T.

If name is set, the instance or builder registered with this name will be get.

See also:

Implementation

T resolve<T>([String? name]) {
  final providers = _providers[name] ?? _ProviderValue.from({});

  if (!silent && !(providers.containsKey(T))) {
    throw NotRegisteredKiwiError(
        'Failed to resolve `$T`:\n\nThe type `$T` was not registered${name == null ? '' : ' for the name `$name`'}\n\nMake sure `$T` is added to your KiwiContainer and rerun build_runner build\n(If you are using the kiwi_generator)\n\nWhen using Flutter, most of the time a hot restart is required to setup the KiwiContainer again.');
  }

  final value = providers[T]?.get(this);
  if (value == null) {
    throw NotRegisteredKiwiError(
        'Failed to resolve `$T`:\n\nThe type `$T` was not registered${name == null ? '' : ' for the name `$name`'}\n\nMake sure `$T` is added to your KiwiContainer and rerun build_runner build\n(If you are using the kiwi_generator)\n\nWhen using Flutter, most of the time a hot restart is required to setup the KiwiContainer again.');
  }

  if (value is T) return value as T;

  throw NotRegisteredKiwiError(
      'Failed to resolve `$T`:\n\nValue was not registered as `$T`\n\nThe type `$T` was not registered${name == null ? '' : ' for the name `$name`'}\n\nMake sure `$T` is added to your KiwiContainer and rerun build_runner build\n(If you are using the kiwi_generator)\n\nWhen using Flutter, most of the time a hot restart is required to setup the KiwiContainer again.');
}