registerInstance<T> method

void registerInstance<T>(
  1. T instance

Registers an instance of an object of the generic type.

All calls to resolve based on this type will always return the registered instance. This in effect creates a singleton.


void registerInstance<T>(T instance) {
  if (_dependencyRegistrations
      .any((r) => identical(r.typeRegistered, Utilities.typeOf<T>()))) {
    throw StateError("The same type cannot be registered twice");
      _RegistrationType.instanceRegistration, T,
      registeredInstance: instance));